接口 TestContextBootstrapper
public interface TestContextBootstrapper
TestContextBootstrapper
defines the SPI for bootstrapping the Spring TestContext Framework.A
TestContextBootstrapper
is used by theTestContextManager
to get the TestExecutionListeners for the current test and to build the TestContext that it manages.Configuration
A custom bootstrapping strategy can be configured for a test class (or test class hierarchy) via
@BootstrapWith
, either directly or as a meta-annotation.If a bootstrapper is not explicitly configured via
@BootstrapWith
, either theDefaultTestContextBootstrapper
or theWebTestContextBootstrapper
will be used, depending on the presence of@WebAppConfiguration
.Implementation Notes
Concrete implementations must provide a
public
no-args constructor.WARNING: this SPI will likely change in the future in order to accommodate new requirements. Implementers are therefore strongly encouraged not to implement this interface directly but rather to extend
AbstractTestContextBootstrapper
or one of its concrete subclasses instead.- 从以下版本开始:
- 4.1
- 作者:
- Sam Brannen
- 另请参阅:
BootstrapWith
,BootstrapContext
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 MergedContextConfiguration
buildMergedContextConfiguration()
Build the merged context configuration for the test class in theBootstrapContext
associated with this bootstrapper.TestContext
buildTestContext()
Build theTestContext
for theBootstrapContext
associated with this bootstrapper.BootstrapContext
getBootstrapContext()
Get theBootstrapContext
associated with this bootstrapper.List<TestExecutionListener>
getTestExecutionListeners()
Get a list of newly instantiatedTestExecutionListeners
for the test class in theBootstrapContext
associated with this bootstrapper.void
setBootstrapContext(BootstrapContext bootstrapContext)
Set theBootstrapContext
to be used by this bootstrapper.
方法详细资料
setBootstrapContext
void setBootstrapContext(BootstrapContext bootstrapContext)
Set theBootstrapContext
to be used by this bootstrapper.
getBootstrapContext
BootstrapContext getBootstrapContext()
Get theBootstrapContext
associated with this bootstrapper.
buildTestContext
TestContext buildTestContext()
Build theTestContext
for theBootstrapContext
associated with this bootstrapper.- 返回:
- a new
TestContext
, nevernull
- 从以下版本开始:
- 4.2
- 另请参阅:
buildMergedContextConfiguration()
buildMergedContextConfiguration
MergedContextConfiguration buildMergedContextConfiguration()
Build the merged context configuration for the test class in theBootstrapContext
associated with this bootstrapper.Implementations must take the following into account when building the merged configuration:
- Context hierarchies declared via
@ContextHierarchy
and@ContextConfiguration
- Active bean definition profiles declared via
@ActiveProfiles
- Context initializers declared via
ContextConfiguration.initializers()
- Test property sources declared via
@TestPropertySource
Consult the Javadoc for the aforementioned annotations for details on the required semantics.
Note that the implementation of
buildTestContext()
should typically delegate to this method when constructing theTestContext
.When determining which
ContextLoader
to use for a given test class, the following algorithm should be used:- If a
ContextLoader
class has been explicitly declared viaContextConfiguration.loader()
, use it. - Otherwise, concrete implementations are free to determine which
ContextLoader
class to use as a default.
- 返回:
- the merged context configuration, never
null
- 另请参阅:
buildTestContext()
- Context hierarchies declared via
getTestExecutionListeners
List<TestExecutionListener> getTestExecutionListeners()
Get a list of newly instantiatedTestExecutionListeners
for the test class in theBootstrapContext
associated with this bootstrapper.If
@TestExecutionListeners
is not present on the test class in theBootstrapContext
, default listeners should be returned. Furthermore, default listeners must be sorted usingAnnotationAwareOrderComparator
.Concrete implementations are free to determine what comprises the set of default listeners. However, by default, the Spring TestContext Framework will use the
SpringFactoriesLoader
mechanism to look up allTestExecutionListener
class names configured in allMETA-INF/spring.factories
files on the classpath.The
inheritListeners
flag of@TestExecutionListeners
must be taken into consideration. Specifically, if theinheritListeners
flag is set totrue
, listeners declared for a given test class must be appended to the end of the list of listeners declared in superclasses.- 返回:
- a list of
TestExecutionListener
instances