Skip to content

Commit e31d947

Browse files
committed
[SPR-5640] Updated reference manual regarding new support for marking the test application context as 'dirty' after each test method within a given test class.
1 parent eef6fd3 commit e31d947

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

spring-framework-reference/src/testing.xml

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,20 +441,50 @@ public class CustomConfiguredApplicationContextTests {
441441
<para><emphasis
442442
role="bold"><interfacename>@DirtiesContext</interfacename></emphasis></para>
443443

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>
452477

453478
<programlisting language="java">@DirtiesContext
454479
public class ContextDirtyingTests {
455480
<lineannotation>// some tests that result in the Spring container being dirtied</lineannotation>
456481
}</programlisting>
457482

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+
458488
<programlisting language="java">@DirtiesContext
459489
@Test
460490
public void testProcessWhichDirtiesAppCtx() {

0 commit comments

Comments
 (0)