public abstract @interface

DirtiesContext

implements Annotation
org.springframework.test.annotation.DirtiesContext

Class Overview

Test annotation which indicates that the ApplicationContext associated with a test is dirty and should be closed:

  • after the current test, when declared at the method level
  • after each test method in the current test class, when declared at the class level with class mode set to AFTER_EACH_TEST_METHOD
  • after the current test class, when declared at the class level with class mode set to AFTER_CLASS

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 DirtiesContext.ClassMode is set to AFTER_EACH_TEST_METHOD, the context will be marked dirty after each test method in the class.

Summary

Nested Classes
enum DirtiesContext.ClassMode Defines modes which determine how @DirtiesContext is interpreted when used to annotate a test class. 
[Expand]
Inherited Methods
From interface java.lang.annotation.Annotation