Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
spring-projects-issues opened this issue Jul 31, 2014 · 1 comment
Closed
5 tasks done
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 31, 2014

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

@spring-projects-issues
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants