Skip to content

Instantly share code, notes, and snippets.

@agoston
Created March 18, 2014 22:07
Show Gist options
  • Save agoston/9630792 to your computer and use it in GitHub Desktop.
Save agoston/9630792 to your computer and use it in GitHub Desktop.
TestExecutionListener for Spring + JUnit tests, similar to @DirtiesContext, but reinitializes context _before_ test class is run. The upside is that you can influence context creating from the @BeforeClass this way.
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
public class ReinitContextTestExecutionListener extends AbstractTestExecutionListener {
@Override
public void beforeTestClass(final TestContext testContext) throws Exception {
testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment