public class DirtiesContextBeforeModesTestExecutionListener extends AbstractDirtiesContextTestExecutionListener
TestExecutionListener
which provides support for marking the
ApplicationContext
associated with a test as dirty for
both test classes and test methods annotated with the
@DirtiesContext
annotation.
This listener supports test methods with the
method mode set to
BEFORE_METHOD
and test classes with the
class mode set to
BEFORE_EACH_TEST_METHOD
or
BEFORE_CLASS
. For support for AFTER
modes, see DirtiesContextTestExecutionListener
.
When merging
TestExecutionListeners
with the defaults, this listener will
automatically be ordered before the DependencyInjectionTestExecutionListener
;
otherwise, this listener must be manually configured to execute before the
DependencyInjectionTestExecutionListener
.
DirtiesContext
,
DirtiesContextTestExecutionListener
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
DirtiesContextBeforeModesTestExecutionListener() |
Modifier and Type | Method and Description |
---|---|
void |
beforeTestClass(TestContext testContext)
If the test class of the supplied test context
is annotated with
@DirtiesContext and the class mode is set to BEFORE_CLASS , 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 |
beforeTestMethod(TestContext testContext)
If the current test method of the supplied test
context is annotated with
@DirtiesContext and the method mode is set to BEFORE_METHOD , or if the test class is
annotated with @DirtiesContext and the class mode is set to BEFORE_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 . |
int |
getOrder()
Returns
1500 . |
beforeOrAfterTestClass, beforeOrAfterTestMethod, dirtyContext
afterTestClass, afterTestExecution, afterTestMethod, beforeTestExecution, prepareTestInstance
public DirtiesContextBeforeModesTestExecutionListener()
public final int getOrder()
1500
.getOrder
in interface Ordered
getOrder
in class AbstractDirtiesContextTestExecutionListener
Ordered.HIGHEST_PRECEDENCE
,
Ordered.LOWEST_PRECEDENCE
public void beforeTestClass(TestContext testContext) throws Exception
@DirtiesContext
and the class mode is set to BEFORE_CLASS
, 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
.beforeTestClass
in interface TestExecutionListener
beforeTestClass
in class AbstractTestExecutionListener
testContext
- the test context for the test; never null
Exception
- allows any exception to propagatepublic void beforeTestMethod(TestContext testContext) throws Exception
@DirtiesContext
and the method mode is set to BEFORE_METHOD
, or if the test class is
annotated with @DirtiesContext
and the class mode is set to BEFORE_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
.beforeTestMethod
in interface TestExecutionListener
beforeTestMethod
in class AbstractTestExecutionListener
testContext
- the test context in which the test method will be
executed; never null
Exception
- allows any exception to propagateTestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
,
TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
,
TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)