Interface TestContextBootstrapper
- All Known Implementing Classes:
AbstractTestContextBootstrapper,DefaultTestContextBootstrapper,WebTestContextBootstrapper
public interface TestContextBootstrapper
TestContextBootstrapperdefines the SPI for bootstrapping the Spring TestContext Framework.A
TestContextBootstrapperis used by theTestContextManagerto 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 theDefaultTestContextBootstrapperor theWebTestContextBootstrapperwill be used, depending on the presence of@WebAppConfiguration.Implementation Notes
Concrete implementations must provide a
publicno-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
AbstractTestContextBootstrapperor one of its concrete subclasses instead.- Since:
- 4.1
- Author:
- Sam Brannen
- See Also:
BootstrapWith,BootstrapContext
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description MergedContextConfigurationbuildMergedContextConfiguration()Build the merged context configuration for the test class in theBootstrapContextassociated with this bootstrapper.TestContextbuildTestContext()Build theTestContextfor theBootstrapContextassociated with this bootstrapper.BootstrapContextgetBootstrapContext()Get theBootstrapContextassociated with this bootstrapper.List<TestExecutionListener>getTestExecutionListeners()Get a list of newly instantiatedTestExecutionListenersfor the test class in theBootstrapContextassociated with this bootstrapper.voidsetBootstrapContext(BootstrapContext bootstrapContext)Set theBootstrapContextto be used by this bootstrapper.
Method Detail
setBootstrapContext
void setBootstrapContext(BootstrapContext bootstrapContext)
Set theBootstrapContextto be used by this bootstrapper.
getBootstrapContext
BootstrapContext getBootstrapContext()
Get theBootstrapContextassociated with this bootstrapper.
buildTestContext
TestContext buildTestContext()
Build theTestContextfor theBootstrapContextassociated with this bootstrapper.- Returns:
- a new
TestContext, nevernull - Since:
- 4.2
- See Also:
buildMergedContextConfiguration()
buildMergedContextConfiguration
MergedContextConfiguration buildMergedContextConfiguration()
Build the merged context configuration for the test class in theBootstrapContextassociated with this bootstrapper.Implementations must take the following into account when building the merged configuration:
- Context hierarchies declared via
@ContextHierarchyand@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
ContextLoaderto use for a given test class, the following algorithm should be used:- If a
ContextLoaderclass has been explicitly declared viaContextConfiguration.loader(), use it. - Otherwise, concrete implementations are free to determine which
ContextLoaderclass to use as a default.
- Returns:
- the merged context configuration, never
null - See Also:
buildTestContext()
- Context hierarchies declared via
getTestExecutionListeners
List<TestExecutionListener> getTestExecutionListeners()
Get a list of newly instantiatedTestExecutionListenersfor the test class in theBootstrapContextassociated with this bootstrapper.If
@TestExecutionListenersis 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
SpringFactoriesLoadermechanism to look up allTestExecutionListenerclass names configured in allMETA-INF/spring.factoriesfiles on the classpath.The
inheritListenersflag of@TestExecutionListenersmust be taken into consideration. Specifically, if theinheritListenersflag is set totrue, listeners declared for a given test class must be appended to the end of the list of listeners declared in superclasses.- Returns:
- a list of
TestExecutionListenerinstances