Spring Framework

org.springframework.test.annotation
Annotation Type DirtiesContext


@Documented
@Inherited
@Retention(value=RUNTIME)
@Target(value={TYPE,METHOD})
public @interface DirtiesContext

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

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.

Since:
2.0
Author:
Sam Brannen, Rod Johnson

Optional Element Summary
 DirtiesContext.ClassMode classMode
          The mode to use when a test class is annotated with @DirtiesContext.
 

classMode

public abstract DirtiesContext.ClassMode classMode
The mode to use when a test class is annotated with @DirtiesContext.

Defaults to AFTER_CLASS.

Note: Setting the class mode on an annotated test method has no meaning, since the mere presence of the @DirtiesContext annotation on a test method is sufficient.

Default:
org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS

Spring Framework