You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Introduce @TestPropertySource support in the TestContext framework [SPR-12051] #16667
#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
Introduce a new @TestPropertySource annotation for configuring a test-specific PropertySource.
@TestPropertySource must support attributes analogous to those found in @PropertySource (i.e., for declaring resource locations).
@TestPropertySource must support an additional attribute that allows for key/value pairs to be declared inline.
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).
The context cache key (i.e., MergedContextConfiguration) must take test property sources into account.
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.
Activity
spring-projects-issues commentedon Aug 13, 2014
Sam Brannen commented
Completed as described in the comments for GitHub commit 2cf4147: