Im writing a TestCases
for my RestControllers
For each ControllerTest calss
I use the following annotations
@WebAppConfiguration
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebConfig.class, TestAppConfig.class})
So, I decided to define my own annotation witch contain all those annotations like this
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@WebAppConfiguration
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebConfig.class, TestAppConfig.class})
public @interface ControllerTest {
}
Then, I used only one annotation for all my ControllerTest classes
@ControllerTest
public class XXControllerTest {
}
After this modification the tests failed with
java.lang.IllegalArgumentException: WebApplicationContext is required
at org.springframework.util.Assert.notNull(Assert.java:115)
And to make it work again it required me to add the @RunWith(SpringJUnit4ClassRunner.class)
to the Test class
@ControllerTest
@RunWith(SpringJUnit4ClassRunner.class)
public class XXControllerTest {
}
My question is why my @ControllerTest
annotation doesn't work while its contain the @RunWith(SpringJUnit4ClassRunner.class)
annotation? is there anything special about the @RunWith
annotation? or did I miss something?
PS: I use the same approach for Spring config classes
and they work just fine.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…