我写一个TestCases
我RestControllers
对于每个ControllerTest calss
我用下面的注解Java自定义注释聚集多个注释
@WebAppConfiguration
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebConfig.class, TestAppConfig.class})
所以,我决定定义自己的注解巫婆包含这样
所有这些注解@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@WebAppConfiguration
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebConfig.class, TestAppConfig.class})
public @interface ControllerTest {
}
然后,我只用一个标注为我所有的ControllerTest classes
@ControllerTest
public class XXControllerTest {
}
这个修改后的测试与
java.lang.IllegalArgumentException: WebApplicationContext is required
at org.springframework.util.Assert.notNull(Assert.java:115)
,未能使其再次工作,它需要我的@RunWith(SpringJUnit4ClassRunner.class)
添加到Test class
@ControllerTest
@RunWith(SpringJUnit4ClassRunner.class)
public class XXControllerTest {
}
我的问题是,为什么我@ControllerTest
注释没有按当它包含@RunWith(SpringJUnit4ClassRunner.class)
注解时不工作? @RunWith
注释有什么特别之处吗?还是我错过了什么?
PS:我使用相同的方法Spring config classes
,他们工作得很好。