-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Allow @PropertySource to be specified on a test class [SPR-10232] #14865
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
Comments
Sam Brannen commented Indeed, an On the other hand, if you're using annotated classes (i.e., I am therefore inclined to close this issue, but I'll leave it open for the time being in order to allow others to comment. Regards, Sam |
Sam Brannen commented Out of curiosity, why did you look to After all, it's not exactly a public API. ;) However, I will update the class-level Javadoc for |
Paul Tomlin commented I looked at ContextLoaderUtils because it's the class that handles the registration of I realize there are a few ways of achieving registration of PropertySources, such as the custom ContextLoader or I don't know how hard it would be to build an ApplicationContextInitializer that looks at the test class for |
Sam Brannen commented Ah, OK. Let me explain the status quo. Support for Thus, at the time of 3.1, However, the added support for In other words, a custom In summary, it all boils down to whether or not there is sufficient added value associated with a declarative approach. - Sam |
Paul Tomlin commented Understood and agreed. +1 for "yes please" ;) |
Sam Brannen commented While analyzing the implementation of In your |
Emerson Farrugia commented Although adding a (possibly nested) |
Sam Brannen commented Please note that this issue has been superseded by #16667. |
Sam Brannen commented If you are following this issue, you might be interested in knowing that #16667 has been resolved. |
Paul Tomlin opened SPR-10232 and commented
Overview
When using the TestContext framework it would be nice to easily be able to specify some
PropertySources
to be added to theEnvironment
, in much the same way as@ActiveProfiles
allows specifying the active profiles.Ideally, something like below would result in a
ResourcePropertySource
being registered with the environment of the test'sApplicationContext
prior to refresh:Work-around
In Spring Framework 3.1, there is a workaround, but it's not nearly as tidy as the above proposal.
There may be something in 3.2.x, probably as a result of #13650 and
ApplicationContextInitializer
, butContextLoaderUtils
doesn't seem to suggest so, and I'm not yet familiar enough to know.Analysis
@ActiveProfiles
,@PropertySource
declarations on test classes should be inherited by default but overridable.@PropertySource
is not an@Inherited
annotation, butAnnotationUtils.findAnnotationDeclaringClass()
should take care of this.@PropertySource
in integration tests must be consistent with the existing behavior in@Configuration
classes.ConfigurationClassPostProcessor
andConfigurationClassParser
below.ConfigurationClassParser.processPropertySource()
should be reused and not duplicated in the testing framework; in other words, consider extracting the existing logic into a static utility method or similar.MergedContextConfiguration
) must take test property sources into account.Relevant code from ConfigurationClassPostProcessor
Relevant code from ConfigurationClassParser
Affects: 3.1 GA
Issue Links:
@Configuration
classes@TestPropertySource
support in the TestContext framework ("is superseded by")Referenced from: commits 3210041
4 votes, 8 watchers
The text was updated successfully, but these errors were encountered: