Skip to content

Introduce @TestPropertySource support in the TestContext framework [SPR-12051] #16667

Closed

Description

@spring-projects-issues

Sam Brannen opened SPR-12051 and commented

Status Quo

#14865 and #16004 proposed support for using @PropertySource on test classes and introducing @TestPropertyValue for declarative PropertySource value declarations, respectively. This issue supersedes those two issues by combining the two proposals into a dedicated @TestPropertySource annotation.


Deliverables

  1. Introduce a new @TestPropertySource annotation for configuring a test-specific PropertySource.
  2. @TestPropertySource must support attributes analogous to those found in @PropertySource (i.e., for declaring resource locations).
  3. @TestPropertySource must support an additional attribute that allows for key/value pairs to be declared inline.
  4. As with @ActiveProfiles, @TestPropertySource declarations on test classes should be inherited by default but overridable via a boolean flag (i.e., attribute in the annotation).
  5. The context cache key (i.e., MergedContextConfiguration) must take test property sources into account.

Further Resources


Issue Links:

Referenced from: commits f2ac025, 2cf4147

1 votes, 3 watchers

Activity

  1. spring-projects-issues commented on Aug 13, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Completed as described in the comments for GitHub commit 2cf4147:

    Introduce @TestPropertySource support in the TCF

    Spring Framework 3.1 introduced an Environment abstraction with support
    for hierarchical PropertySources that can be configured
    programmatically as well as declaratively via the @PropertySource
    annotation. However, prior to this commit, there was no way to
    declaratively configure PropertySources in integration tests in the
    Spring TestContext Framework (TCF).

    This commit introduces declarative support for PropertySources in the
    TCF via a new class-level @TestPropertySource annotation. This
    annotation provides two options for declaring test property sources:

    • The 'locations' attribute allows developers to declare external
      resource locations for test properties files.

    • The 'properties' attribute allows developers to declare inlined
      properties in the form of key-value pairs.

    Test properties files are added to the Environment before all other
    property sources and can therefore override system and application
    property sources. Similarly, inlined properties are added to the
    Environment before all other property sources and can therefore
    override system property sources, application property sources, and
    test properties files.

    Specifically, this commit introduces the following major changes:

    • Introduced @TestPropertySource annotation along with internal
      TestPropertySourceAttributes, MergedTestPropertySources, and
      TestPropertySourceUtils for working with test property sources
      within the TCF.

    • All TestContextBootstrappers have been modified to support the
      merged property resource locations and inlined properties from
      @TestPropertySource.

    • MergedContextConfiguration (and consequently the context caching
      key) is now additionally based on the merged property resource
      locations and inlined properties from @TestPropertySource. The same
      applies to WebMergedContextConfiguration.

    • AbstractContextLoader's prepareContext() method now adds
      PropertySources for all resource locations and inlined properties
      from the supplied MergedContextConfiguration to the Environment of
      the supplied ApplicationContext. All subclasses of
      AbstractGenericContextLoader and AbstractGenericWebContextLoader
      therefore automatically provide support for @TestPropertySource.

  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