Skip to content

Commit d7d0292

Browse files
committed
Document @DirtiesContext semantics when declared at class & method level
Closes gh-30623
1 parent 2817dce commit d7d0292

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-dirtiescontext.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ metadata.
1212
You can use `@DirtiesContext` as both a class-level and a method-level annotation within
1313
the same class or class hierarchy. In such scenarios, the `ApplicationContext` is marked
1414
as dirty before or after any such annotated method as well as before or after the current
15-
test class, depending on the configured `methodMode` and `classMode`.
15+
test class, depending on the configured `methodMode` and `classMode`. When
16+
`@DirtiesContext` is declared at both the class level and the method level, the
17+
configured modes from both annotations will be honored. For example, if the class mode is
18+
set to `BEFORE_EACH_TEST_METHOD` and the method mode is set to `AFTER_METHOD`, the
19+
context will be marked as dirty both before and after the given test method.
1620

1721
The following examples explain when the context would be dirtied for various
1822
configuration scenarios:

spring-test/src/main/java/org/springframework/test/annotation/DirtiesContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
* {@code ApplicationContext} will be marked as <em>dirty</em> before or
4040
* after any such annotated method as well as before or after the current test
4141
* class, depending on the configured {@link #methodMode} and {@link #classMode}.
42+
* When {@code @DirtiesContext} is declared at both the class level and the
43+
* method level, the configured test phases from both annotations will be honored.
44+
* For example, if the class mode is set to {@link ClassMode#BEFORE_EACH_TEST_METHOD
45+
* BEFORE_EACH_TEST_METHOD} and the method mode is set to
46+
* {@link MethodMode#AFTER_METHOD AFTER_METHOD}, the context will be marked as
47+
* dirty both before and after the given test method.
4248
*
4349
* <h3>Supported Test Phases</h3>
4450
* <ul>

0 commit comments

Comments
 (0)