public class TestContext extends AttributeAccessorSupport
TestContext
encapsulates the context in which a test is executed,
agnostic of the actual testing framework in use.Modifier and Type | Field and Description |
---|---|
private CacheAwareContextLoaderDelegate |
cacheAwareContextLoaderDelegate |
private ContextCache |
contextCache |
private static Log |
logger |
private MergedContextConfiguration |
mergedContextConfiguration |
private static long |
serialVersionUID |
private java.lang.Class<?> |
testClass |
private java.lang.Throwable |
testException |
private java.lang.Object |
testInstance |
private java.lang.reflect.Method |
testMethod |
Constructor and Description |
---|
TestContext(java.lang.Class<?> testClass,
ContextCache contextCache)
Delegates to
TestContext(Class, ContextCache, String) with a
value of null for the default ContextLoader class name. |
TestContext(java.lang.Class<?> testClass,
ContextCache contextCache,
java.lang.String defaultContextLoaderClassName)
Construct a new test context for the supplied test class
and context cache and parse the corresponding
@ContextConfiguration or
@ContextHierarchy annotation, if present. |
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()
Deprecated.
as of Spring 3.2.2; use
markApplicationContextDirty(DirtiesContext.HierarchyMode) instead. |
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.
|
java.lang.String |
toString()
Provide a String representation of this test context's state.
|
(package private) 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, copyAttributesFrom, equals, getAttribute, hasAttribute, hashCode, removeAttribute, setAttribute
private static final long serialVersionUID
private static final Log logger
private final ContextCache contextCache
private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate
private final MergedContextConfiguration mergedContextConfiguration
private final java.lang.Class<?> testClass
private java.lang.Object testInstance
private java.lang.reflect.Method testMethod
private java.lang.Throwable testException
TestContext(java.lang.Class<?> testClass, ContextCache contextCache)
TestContext(Class, ContextCache, String)
with a
value of null
for the default ContextLoader
class name.TestContext(java.lang.Class<?> testClass, ContextCache contextCache, java.lang.String defaultContextLoaderClassName)
@ContextConfiguration
or
@ContextHierarchy
annotation, if present.
If the supplied class name for the default ContextLoader
is null
or empty and no concrete ContextLoader
class is explicitly supplied via @ContextConfiguration
, a
DelegatingSmartContextLoader
or
WebDelegatingSmartContextLoader
will be used instead.
testClass
- the test class for which the test context should be
constructed (must not be null
)contextCache
- the context cache from which the constructed test
context should retrieve application contexts (must not be
null
)defaultContextLoaderClassName
- the name of the default
ContextLoader
class to use (may be null
)public ApplicationContext getApplicationContext()
application context
for this test
context, possibly cached.java.lang.IllegalStateException
- if an error occurs while retrieving the
application contextpublic final java.lang.Class<?> getTestClass()
test class
for this test context.null
)public final java.lang.Object getTestInstance()
test instance
for this test context.
Note: this is a mutable property.
null
)updateState(Object, Method, Throwable)
public final java.lang.reflect.Method getTestMethod()
test method
for this test context.
Note: this is a mutable property.
null
)updateState(Object, Method, Throwable)
public final 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)
@Deprecated public void markApplicationContextDirty()
markApplicationContextDirty(DirtiesContext.HierarchyMode)
instead.public 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)
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 thrownpublic java.lang.String toString()
toString
in class java.lang.Object