TransactionalIntegrationTest.java
@TestMethodOrder(OrderAnnotation.class)
@SpringJUnitWebConfig(locations = { "classpath:service.xml","classpath:data.xml" })
@Tag("1")
public @interface TransactionalIntegrationTest {}
MyTestTest .java
@TransactionalIntegrationTest
public class MyTestTest {
@Autowired
protected CreateUser createUser;
@BeforeEach
public void setUp() throws Exception {
createUser.createTimesheetUser(...)} --> NPE
}
在
createUser
上获取NullPointerException。如果我不使用元注释,那么它将正常工作。
MyTestTest.java
@TestMethodOrder(OrderAnnotation.class)
@SpringJUnitWebConfig(locations = { "classpath:service.xml","classpath:data.xml" })
@Tag("1")
public class MyTestTest {
@Autowired
protected CreateUser createUser;
@BeforeEach
public void setUp() throws Exception {
createUser.createTimesheetUser(...)} --> works now
}
最佳答案
您可能会丢失@Retention
声明,该声明允许诸如Spring和JUnit之类的框架在运行时查看批注。
如下声明您组成的注释应该起作用。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@TestMethodOrder(OrderAnnotation.class)
@SpringJUnitWebConfig(locations = { "classpath:service.xml", "classpath:data.xml" })
@Tag("1")
public @interface TransactionalIntegrationTest {
}