I use the SpringJUnit4ClassRunner
for writing integration tests. I also use @DirtiesContext
for tests that leave the context in an broken state behind
As of Spring 4.2 the DirtiesContext annotation supports the following new phases: BEFORE_CLASS, BEFORE_EACH_TEST_METHOD and BEFORE_METHOD. So you can now do for example:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(...)
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public class MyTest {
..
}