org.springframework.test.context.support

## Class DirtiesContextTestExecutionListener

- java.lang.Object
- - org.springframework.test.context.support.AbstractTestExecutionListener
  - - org.springframework.test.context.support.DirtiesContextTestExecutionListener

All Implemented Interfaces:
  TestExecutionListener

    public class DirtiesContextTestExecutionListener
    extends AbstractTestExecutionListener

`TestExecutionListener` which provides support for marking the `ApplicationContext` associated with a test as dirty for both test classes and test methods configured with the `@DirtiesContext` annotation.

Since:
  2.5
Author:
  Sam Brannen, Juergen Hoeller
See Also:
  `DirtiesContext`

### Constructor Summary

Constructors
Constructor and Description
`DirtiesContextTestExecutionListener()`

### Method Summary

Methods
`void` `afterTestClass(TestContext testContext)` If the test class of the supplied `test context` is annotated with `@DirtiesContext`, the `application context` of the test context will be `marked as dirty` , and the `REINJECT_DEPENDENCIES_ATTRIBUTE` in the test context will be set to `true`.

`void`

`afterTestMethod(TestContext testContext)`
If the current test method of the supplied `test context` is annotated with `@DirtiesContext`, or if the test class is annotated with `@DirtiesContext` and the `class mode` is set to `AFTER_EACH_TEST_METHOD`, the `application context` of the test context will be `marked as dirty` and the `REINJECT_DEPENDENCIES_ATTRIBUTE` in the test context will be set to `true`.

`protected void` `dirtyContext(TestContext testContext)` Marks the `application context` of the supplied `test context` as `dirty`, and sets the `REINJECT_DEPENDENCIES_ATTRIBUTE` in the test context to `true`.

### Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener

`beforeTestClass, beforeTestMethod, prepareTestInstance`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DirtiesContextTestExecutionListener

    public DirtiesContextTestExecutionListener()

### Method Detail

#### dirtyContext

    protected void dirtyContext(TestContext testContext)

Marks the `application context` of the supplied `test context` as `dirty`, and sets the `REINJECT_DEPENDENCIES_ATTRIBUTE` in the test context to `true`.

#### afterTestMethod

    public void afterTestMethod(TestContext testContext)
                         throws Exception

If the current test method of the supplied `test context` is annotated with `@DirtiesContext`, or if the test class is annotated with `@DirtiesContext` and the `class mode` is set to `AFTER_EACH_TEST_METHOD`, the `application context` of the test context will be `marked as dirty` and the `REINJECT_DEPENDENCIES_ATTRIBUTE` in the test context will be set to `true`.

Specified by:
  `afterTestMethod` in interface `TestExecutionListener`
Overrides:
  `afterTestMethod` in class `AbstractTestExecutionListener`
Parameters:
  `testContext` - the test context in which the test method was executed; never `null`
Throws:
  `Exception` - allows any exception to propagate

#### afterTestClass

    public void afterTestClass(TestContext testContext)
                        throws Exception

If the test class of the supplied `test context` is annotated with `@DirtiesContext`, the `application context` of the test context will be `marked as dirty` , and the `REINJECT_DEPENDENCIES_ATTRIBUTE` in the test context will be set to `true`.

Specified by:
  `afterTestClass` in interface `TestExecutionListener`
Overrides:
  `afterTestClass` in class `AbstractTestExecutionListener`
Parameters:
  `testContext` - the test context for the test; never `null`
Throws:
  `Exception` - allows any exception to propagate