public interface TestContext extends AttributeAccessor, java.io.Serializable
TestContext
encapsulates the context in which a test is executed,
agnostic of the actual testing framework in use.Modifier and Type | Method and Description |
---|---|
ApplicationContext |
getApplicationContext()
Get the
application context for this test
context, possibly cached. |
java.lang.Class<?> |
getTestClass()
Get the
test class for this test context. |
java.lang.Throwable |
getTestException()
Get the
exception that was thrown during execution of
the test method . |
java.lang.Object |
getTestInstance()
Get the current
test instance for this test context. |
java.lang.reflect.Method |
getTestMethod()
Get the current
test method for this test context. |
void |
markApplicationContextDirty(DirtiesContext.HierarchyMode hierarchyMode)
Call this method to signal that the application
context associated with this test context is dirty and should be
discarded.
|
void |
updateState(java.lang.Object testInstance,
java.lang.reflect.Method testMethod,
java.lang.Throwable testException)
Update this test context to reflect the state of the currently executing
test.
|
attributeNames, getAttribute, hasAttribute, removeAttribute, setAttribute
ApplicationContext getApplicationContext()
application context
for this test
context, possibly cached.
Implementations of this method are responsible for loading the application context if the corresponding context has not already been loaded, potentially caching the context as well.
java.lang.IllegalStateException
- if an error occurs while retrieving the
application contextjava.lang.Class<?> getTestClass()
test class
for this test context.null
)java.lang.Object getTestInstance()
test instance
for this test context.
Note: this is a mutable property.
null
)updateState(Object, Method, Throwable)
java.lang.reflect.Method getTestMethod()
test method
for this test context.
Note: this is a mutable property.
null
)updateState(Object, Method, Throwable)
java.lang.Throwable getTestException()
exception
that was thrown during execution of
the test method
.
Note: this is a mutable property.
null
if no
exception was thrownupdateState(Object, Method, Throwable)
void markApplicationContextDirty(DirtiesContext.HierarchyMode hierarchyMode)
hierarchyMode
- the context cache clearing mode to be applied if the
context is part of a hierarchy (may be null
)void updateState(java.lang.Object testInstance, java.lang.reflect.Method testMethod, java.lang.Throwable testException)
Caution: concurrent invocations of this method might not be thread-safe, depending on the underlying implementation.
testInstance
- the current test instance (may be null
)testMethod
- the current test method (may be null
)testException
- the exception that was thrown in the test method, or
null
if no exception was thrown