Spring Framework 4.2.0.RELEASE has arrived and two new rules have been added to spring-framework project SpringClassRule and SpringMethodRule.
In spring applications we have used SpringJUnit4ClassRunner for a long time in our tests but JUnit only support one Runner at the time, in order to allow integration between spring with other Runners like org.junit.runners.Parameterized we can use these new classes instead of @RunWith(SpringJUnit4ClassRunner.class)
SpringClassRuleenable the following annotations@BeforeClass,@AfterClass,@ProfileValueSourceConfiguration,@IfProfileValue.SpringMethodRuleenable the following annotations@Before,@After,@Repeat,@Timeout,@ProfileValueSourceConfiguration,@IfProfileValue.
Test using classic SpringJUnit4ClassRunner.
1 2 3 4 5 6 7 8 9 | |
Test using new rules SpringClassRule and SpringMethodRule.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Both have the same effect in your test and you can use them in different context.