Issue
I am using @TestPropertySource to overwrite application.yml properties in my integration test for a spring boot app.
@TestPropertySource(properties = { "repository.file.path=src/test/resources/x" })
I was wondering if there was some way to make the property VALUE dynamic. Something like this:
@TestPropertySource(properties = { "repository.file.path=PropertyValueProvider.class" })
Your feedback is appreciated. In my case the property value is system specific that should be generated upon the test run.
Solution
@TestPropertySource
only provides declarative mechanisms for configuring PropertySource
s. Documentation in Spring Reference Manual.
If you need programmatic support for adding a PropertySource
to the Environment
, you should implement an ApplicationContextInitializer
which can be registered via @ContextConfiguration(initializers = ...)
. Documentation in Spring Reference Manual.
Regards,
Sam (author of the Spring TestContext Framework)
Answered By - Sam Brannen
Answer Checked By - Mary Flores (JavaFixing Volunteer)