@@ -441,20 +441,50 @@ public class CustomConfiguredApplicationContextTests {
441
441
<para ><emphasis
442
442
role =" bold" ><interfacename >@DirtiesContext</interfacename ></emphasis ></para >
443
443
444
- <para >The presence of this annotation on a test method indicates
445
- that the underlying Spring container has been <emphasis >dirtied</emphasis >
446
- during the execution of the test method and thus must be closed after the
447
- test method finishes execution (regardless of whether the annotated test
448
- passed or not). Similarly, if a test class is annotated with
449
- <interfacename >@DirtiesContext</interfacename >, the underlying
450
- Spring container will be marked as dirty after all tests in the
451
- class have completed execution.</para >
444
+ <para >Indicates that the underlying Spring
445
+ <interfacename >ApplicationContext</interfacename > has been
446
+ <emphasis >dirtied</emphasis > during the execution of a test and
447
+ should be closed (regardless of whether the test passed or not):</para >
448
+
449
+ <itemizedlist >
450
+ <listitem >
451
+ <para >after the current test class, when declared on a
452
+ class with class mode set to <literal >AFTER_CLASS</literal >,
453
+ which is the default class mode</para >
454
+ </listitem >
455
+ <listitem >
456
+ <para >after each test method in the current test class,
457
+ when declared on a class with class mode set to
458
+ <literal >AFTER_EACH_TEST_METHOD</literal ></para >
459
+ </listitem >
460
+ <listitem >
461
+ <para >after the current test, when declared on a method</para >
462
+ </listitem >
463
+ </itemizedlist >
464
+
465
+ <para >Use this annotation if a test has modified the context
466
+ (for example, by replacing a bean definition). Subsequent tests
467
+ will be supplied a new context.</para >
468
+
469
+ <para ><interfacename >@DirtiesContext</interfacename > may be used
470
+ as a class-level and method-level annotation within the same class.
471
+ In such scenarios, the <interfacename >ApplicationContext</interfacename >
472
+ will be marked as <emphasis >dirty</emphasis > after any such
473
+ annotated method as well as after the entire class. If the
474
+ <classname >ClassMode</classname > is set to
475
+ <literal >AFTER_EACH_TEST_METHOD</literal >, the context will be
476
+ marked dirty after each test method in the class.</para >
452
477
453
478
<programlisting language =" java" >@DirtiesContext
454
479
public class ContextDirtyingTests {
455
480
<lineannotation >// some tests that result in the Spring container being dirtied</lineannotation >
456
481
}</programlisting >
457
482
483
+ <programlisting language =" java" >@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
484
+ public class ContextDirtyingTests {
485
+ <lineannotation >// some tests that result in the Spring container being dirtied</lineannotation >
486
+ }</programlisting >
487
+
458
488
<programlisting language =" java" >@DirtiesContext
459
489
@Test
460
490
public void testProcessWhichDirtiesAppCtx() {
0 commit comments