Skip to content

Introduce bootstrap strategy in the TestContext framework [SPR-9955] #14588

Closed

Description

@spring-projects-issues

Sam Brannen opened SPR-9955 and commented

Status Quo

Work done in conjunction with #9917 and #9265 introduced physical package cycles in the spring-test module. The work performed in conjunction with #14557 uses reflection to resolve these physical package cycles; however, logical package cycles still remain.

Deliverables

  1. Introduce a bootstrap strategy in the TestContext framework (TCF) that is responsible for determining and appropriately delegating to or instantiating the following:
    • AbstractDelegatingSmartContextLoader (i.e., a concrete subclass thereof)
    • MergedContextConfiguration (or a subclass thereof)
  2. Refactor ContextLoaderUtils to instantiate and delegate to a bootstrap instance instead of using extensive reflection.
  3. Introduce a meta-annotation that can be used to designate the concrete bootstrap strategy to use.
    • For example, @WebAppConfiguration could be annotated with such a meta-annotation that points to the web bootstrap strategy implementation.

Affects: 3.2 RC1

Issue Links:

Referenced from: commits b308659, a281bdb

Activity

  1. spring-projects-issues commented on Apr 9, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Completed as described in the comments for GitHub commit a281bdb:

    Introduce context bootstrap strategy in the TCF

    Work done in conjunction with #9917 and #9265 introduced physical
    package cycles in the spring-test module. The work performed in
    conjunction with #14557 uses reflection to resolve these physical
    package cycles; however, prior to this commit the logical package
    cycles still remain.

    Furthermore, over time it has become apparent that the Spring
    TestContext Framework (TCF) could better serve application developers
    and especially third-party framework developers by providing a more
    flexible mechanism for "bootstrapping" the TCF. For example, prior to
    this commit, default TestExecutionListeners could only be registered by
    subclassing TestContextManager (and SpringJUnit4ClassRunner if using
    JUnit). Similarly, the default ContextLoader could only be set by
    subclassing SpringJUnit4ClassRunner for JUnit and by copying and
    modifying AbstractTestNGSpringContextTests for TestNG.

    This commit addresses the aforementioned issues by introducing a
    bootstrap strategy in the TestContext framework that is responsible for
    determining default TestExecutionListeners and the default
    ContextLoader in an extensible fashion. The new TestContextBootstrapper
    SPI also provides a mechanism for supporting various types of
    MergedContextConfiguration depending on the feature set of the context
    loaders supported by the strategy.

    The following provides an overview of the most significant changes in
    this commit.

    • Introduced TestContextBootstrapper strategy SPI, BootstrapContext,
      and @BootstrapWith.

    • Introduced AbstractTestContextBootstrapper,
      DefaultTestContextBootstrapper, and WebTestContextBootstrapper
      implementations of the TestContextBootstrapper SPI and extracted
      related reflection code from ContextLoaderUtils & TestContextManager.

    • Introduced BootstrapUtils for retrieving the TestContextBootstrapper
      from @BootstrapWith, falling back to a default if @BootstrapWith is
      not present.

    • @WebAppConfiguration is now annotated with
      @BootstrapWith(WebTestContextBootstrapper.class).

    • CacheAwareContextLoaderDelegate is now an interface with a new
      DefaultCacheAwareContextLoaderDelegate implementation class.

    • Introduced closeContext(MergedContextConfiguration, HierarchyMode) in
      CacheAwareContextLoaderDelegate.

    • DefaultTestContext now uses CacheAwareContextLoaderDelegate instead
      of interacting directly with the ContextCache.

    • DefaultTestContext now delegates to a TestContextBootstrapper for
      building the MergedContextConfiguration.

    • TestContextManager now delegates to TestContextBootstrapper for
      retrieving TestExecutionListeners.

    • Deleted TestContextManager(Class, String) constructor and
      SpringJUnit4ClassRunner.getDefaultContextLoaderClassName(Class)
      method since default ContextLoader support is now implemented by
      TestContextBootstrappers.

    • Extracted ActiveProfilesUtils from ContextLoaderUtils.

    • Extracted ApplicationContextInitializerUtils from ContextLoaderUtils.

    • MetaAnnotationUtils is now a public utility class in the test.util
      package.

    • Removed restriction in @ActiveProfiles that a custom resolver cannot
      be used with the 'value' or 'profiles' attributes.

    • Introduced DefaultActiveProfilesResolver.

  2. added
    in: test
    type: enhancement
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: testtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions