接口 TestContext
- 所有超级接口:
AttributeAccessor
,Serializable
- 所有已知实现类:
DefaultTestContext
public interface TestContext extends AttributeAccessor, Serializable
TestContext
encapsulates the context in which a test is executed, agnostic of the actual testing framework in use.- 从以下版本开始:
- 2.5
- 作者:
- Sam Brannen
- 另请参阅:
TestContextManager
,TestExecutionListener
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 ApplicationContext
getApplicationContext()
Get the application context for this test context, possibly cached.Class<?>
getTestClass()
Get the test class for this test context.Throwable
getTestException()
Get the exception that was thrown during execution of the test method.Object
getTestInstance()
Get the current test instance for this test context.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 removed from the context cache.void
updateState(Object testInstance, Method testMethod, Throwable testException)
Update this test context to reflect the state of the currently executing test.从接口继承的方法 org.springframework.core.AttributeAccessor
attributeNames, getAttribute, hasAttribute, removeAttribute, setAttribute
方法详细资料
getApplicationContext
ApplicationContext getApplicationContext()
Get the 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.
- 返回:
- the application context (never
null
) - 抛出:
IllegalStateException
- if an error occurs while retrieving the application context
getTestClass
Class<?> getTestClass()
Get the test class for this test context.- 返回:
- the test class (never
null
)
getTestInstance
Object getTestInstance()
Get the current test instance for this test context.Note: this is a mutable property.
- 返回:
- the current test instance (may be
null
) - 另请参阅:
updateState(Object, Method, Throwable)
getTestMethod
Method getTestMethod()
Get the current test method for this test context.Note: this is a mutable property.
- 返回:
- the current test method (may be
null
) - 另请参阅:
updateState(Object, Method, Throwable)
getTestException
Throwable getTestException()
Get the exception that was thrown during execution of the test method.Note: this is a mutable property.
- 返回:
- the exception that was thrown, or
null
if no exception was thrown - 另请参阅:
updateState(Object, Method, Throwable)
markApplicationContextDirty
void markApplicationContextDirty(DirtiesContext.HierarchyMode hierarchyMode)
Call this method to signal that the application context associated with this test context is dirty and should be removed from the context cache.Do this if a test has modified the context — for example, by modifying the state of a singleton bean, modifying the state of an embedded database, etc.
- 参数:
hierarchyMode
- the context cache clearing mode to be applied if the context is part of a hierarchy (may benull
)
updateState
void updateState(Object testInstance, Method testMethod, Throwable testException)
Update this test context to reflect the state of the currently executing test.Caution: concurrent invocations of this method might not be thread-safe, depending on the underlying implementation.
- 参数:
testInstance
- the current test instance (may benull
)testMethod
- the current test method (may benull
)testException
- the exception that was thrown in the test method, ornull
if no exception was thrown