public interface TestContextBootstrapper
TestContextBootstrapper defines a strategy SPI for bootstrapping the
Spring TestContext Framework.
A custom bootstrapping strategy can be configured for a test class via
@BootstrapWith, either directly or as a meta-annotation.
See @WebAppConfiguration
for an example.
The TestContextManager uses a TestContextBootstrapper to
get the TestExecutionListeners for the
current test and to build the
merged context configuration necessary to create the TestContext that
it manages.
Concrete implementations must provide a public no-args constructor.
Note: this SPI might potentially 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.
BootstrapWith,
BootstrapContext| Modifier and Type | Method and Description |
|---|---|
MergedContextConfiguration |
buildMergedContextConfiguration()
Build the merged context configuration
for the test class in the
BootstrapContext associated with this
bootstrapper. |
BootstrapContext |
getBootstrapContext()
Get the
BootstrapContext associated with this bootstrapper. |
List<TestExecutionListener> |
getTestExecutionListeners()
Get a list of newly instantiated
TestExecutionListeners
for the test class in the BootstrapContext associated with this bootstrapper. |
void |
setBootstrapContext(BootstrapContext bootstrapContext)
Set the
BootstrapContext to be used by this bootstrapper. |
void setBootstrapContext(BootstrapContext bootstrapContext)
BootstrapContext to be used by this bootstrapper.BootstrapContext getBootstrapContext()
BootstrapContext associated with this bootstrapper.List<TestExecutionListener> getTestExecutionListeners()
TestExecutionListeners
for the test class in the BootstrapContext associated with this bootstrapper.
If @TestExecutionListeners is not
present on the test class in the BootstrapContext,
default listeners should be returned. Furthermore, default
listeners must be sorted using
AnnotationAwareOrderComparator.
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 all TestExecutionListener class names
configured in all META-INF/spring.factories files on the classpath.
The inheritListeners
flag of @TestExecutionListeners must be
taken into consideration. Specifically, if the inheritListeners
flag is set to true, listeners declared for a given test class must
be appended to the end of the list of listeners declared in superclasses.
TestExecutionListener instancesMergedContextConfiguration buildMergedContextConfiguration()
BootstrapContext associated with this
bootstrapper.
Implementations must take the following into account when building the merged configuration:
@ContextHierarchy
and @ContextConfiguration@ActiveProfilesContextConfiguration.initializers()Consult the Javadoc for the aforementioned annotations for details on the required semantics.
When determining which ContextLoader to use for a given test
class, the following algorithm should be used:
ContextLoader class has been explicitly declared via
ContextConfiguration.loader(), use it.ContextLoader class to use as as default.null