Interface TestContextBootstrapper

All Known Implementing Classes:
AbstractTestContextBootstrapper, DefaultTestContextBootstrapper, WebTestContextBootstrapper

public interface TestContextBootstrapper
TestContextBootstrapper defines the SPI for bootstrapping the Spring TestContext Framework.

A TestContextBootstrapper is used by the TestContextManager 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 the DefaultTestContextBootstrapper or the WebTestContextBootstrapper 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.

Since:
4.1
Author:
Sam Brannen
See Also:
  • Method Details

    • setBootstrapContext

      void setBootstrapContext(BootstrapContext bootstrapContext)
      Set the BootstrapContext to be used by this bootstrapper.
    • getBootstrapContext

      BootstrapContext getBootstrapContext()
      Get the BootstrapContext associated with this bootstrapper.
    • buildTestContext

      TestContext buildTestContext()
      Build the TestContext for the BootstrapContext associated with this bootstrapper.
      Returns:
      a new TestContext, never null
      Since:
      4.2
      See Also:
    • buildMergedContextConfiguration

      MergedContextConfiguration buildMergedContextConfiguration()
      Build the merged context configuration for the test class in the BootstrapContext associated with this bootstrapper.

      Implementations must take the following into account when building the merged configuration:

      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 the TestContext.

      When determining which ContextLoader to use for a given test class, the following algorithm should be used:

      1. If a ContextLoader class has been explicitly declared via ContextConfiguration.loader(), use it.
      2. Otherwise, concrete implementations are free to determine which ContextLoader class to use as a default.
      Returns:
      the merged context configuration, never null
      See Also:
    • getTestExecutionListeners

      List<TestExecutionListener> getTestExecutionListeners()
      Get a list of newly instantiated 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 or enclosing classes.

      Returns:
      a list of TestExecutionListener instances