类 DefaultTestContext
- java.lang.Object
- org.springframework.core.AttributeAccessorSupport
- org.springframework.test.context.support.DefaultTestContext
- 所有已实现的接口:
Serializable
,AttributeAccessor
,TestContext
public class DefaultTestContext extends AttributeAccessorSupport implements TestContext
Default implementation of theTestContext
interface.- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Juergen Hoeller
- 另请参阅:
- 序列化表格
构造器概要
构造器 构造器 说明 DefaultTestContext(Class<?> testClass, MergedContextConfiguration mergedContextConfiguration, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate)
Construct a newDefaultTestContext
from the supplied arguments.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ApplicationContext
getApplicationContext()
Get the application context for this test context.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)
Mark the application context associated with this test context as dirty (i.e., by removing it from the context cache and closing it).String
toString()
Provide a String representation of this test context's state.void
updateState(Object testInstance, Method testMethod, Throwable testException)
Update this test context to reflect the state of the currently executing test.从类继承的方法 org.springframework.core.AttributeAccessorSupport
attributeNames, copyAttributesFrom, equals, getAttribute, hasAttribute, hashCode, removeAttribute, setAttribute
从接口继承的方法 org.springframework.core.AttributeAccessor
attributeNames, getAttribute, hasAttribute, removeAttribute, setAttribute
构造器详细资料
DefaultTestContext
public DefaultTestContext(Class<?> testClass, MergedContextConfiguration mergedContextConfiguration, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate)
Construct a newDefaultTestContext
from the supplied arguments.- 参数:
testClass
- the test class for this test context; nevernull
mergedContextConfiguration
- the merged application context configuration for this test context; nevernull
cacheAwareContextLoaderDelegate
- the delegate to use for loading and closing the application context for this test context; nevernull
方法详细资料
getApplicationContext
public ApplicationContext getApplicationContext()
Get the application context for this test context.The default implementation delegates to the
CacheAwareContextLoaderDelegate
that was supplied when thisTestContext
was constructed.- 指定者:
getApplicationContext
在接口中TestContext
- 返回:
- the application context (never
null
) - 抛出:
IllegalStateException
- if the context returned by the context loader delegate is not active (i.e., has been closed).- 另请参阅:
CacheAwareContextLoaderDelegate.loadContext(org.springframework.test.context.MergedContextConfiguration)
markApplicationContextDirty
public void markApplicationContextDirty(DirtiesContext.HierarchyMode hierarchyMode)
Mark the application context associated with this test context as dirty (i.e., by removing it from the context cache and closing it).The default implementation delegates to the
CacheAwareContextLoaderDelegate
that was supplied when thisTestContext
was constructed.- 指定者:
markApplicationContextDirty
在接口中TestContext
- 参数:
hierarchyMode
- the context cache clearing mode to be applied if the context is part of a hierarchy (may benull
)- 另请参阅:
CacheAwareContextLoaderDelegate.closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
getTestClass
public final Class<?> getTestClass()
从接口复制的说明:TestContext
Get the test class for this test context.- 指定者:
getTestClass
在接口中TestContext
- 返回:
- the test class (never
null
)
getTestInstance
public final Object getTestInstance()
从接口复制的说明:TestContext
Get the current test instance for this test context.Note: this is a mutable property.
- 指定者:
getTestInstance
在接口中TestContext
- 返回:
- the current test instance (may be
null
) - 另请参阅:
TestContext.updateState(Object, Method, Throwable)
getTestMethod
public final Method getTestMethod()
从接口复制的说明:TestContext
Get the current test method for this test context.Note: this is a mutable property.
- 指定者:
getTestMethod
在接口中TestContext
- 返回:
- the current test method (may be
null
) - 另请参阅:
TestContext.updateState(Object, Method, Throwable)
getTestException
public final Throwable getTestException()
从接口复制的说明:TestContext
Get the exception that was thrown during execution of the test method.Note: this is a mutable property.
- 指定者:
getTestException
在接口中TestContext
- 返回:
- the exception that was thrown, or
null
if no exception was thrown - 另请参阅:
TestContext.updateState(Object, Method, Throwable)
updateState
public void updateState(Object testInstance, Method testMethod, Throwable testException)
从接口复制的说明:TestContext
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.
- 指定者:
updateState
在接口中TestContext
- 参数:
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