diff --git a/spring-framework-reference/src/testing.xml b/spring-framework-reference/src/testing.xml index 820737996b..596ffeeb1d 100644 --- a/spring-framework-reference/src/testing.xml +++ b/spring-framework-reference/src/testing.xml @@ -441,20 +441,50 @@ public class CustomConfiguredApplicationContextTests { @DirtiesContext - The presence of this annotation on a test method indicates - that the underlying Spring container has been dirtied - during the execution of the test method and thus must be closed after the - test method finishes execution (regardless of whether the annotated test - passed or not). Similarly, if a test class is annotated with - @DirtiesContext, the underlying - Spring container will be marked as dirty after all tests in the - class have completed execution. + Indicates that the underlying Spring + ApplicationContext has been + dirtied during the execution of a test and + should be closed (regardless of whether the test passed or not): + + + + after the current test class, when declared on a + class with class mode set to AFTER_CLASS, + which is the default class mode + + + after each test method in the current test class, + when declared on a class with class mode set to + AFTER_EACH_TEST_METHOD + + + after the current test, when declared on a method + + + + Use this annotation if a test has modified the context + (for example, by replacing a bean definition). Subsequent tests + will be supplied a new context. + + @DirtiesContext may be used + as a class-level and method-level annotation within the same class. + In such scenarios, the ApplicationContext + will be marked as dirty after any such + annotated method as well as after the entire class. If the + ClassMode is set to + AFTER_EACH_TEST_METHOD, the context will be + marked dirty after each test method in the class. @DirtiesContext public class ContextDirtyingTests { // some tests that result in the Spring container being dirtied } + @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +public class ContextDirtyingTests { + // some tests that result in the Spring container being dirtied +} + @DirtiesContext @Test public void testProcessWhichDirtiesAppCtx() {