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.
@TestPropertySource
only provides declarative mechanisms for configuringPropertySource
s. Documentation in Spring Reference Manual.If you need programmatic support for adding a
PropertySource
to theEnvironment
, you should implement anApplicationContextInitializer
which can be registered via@ContextConfiguration(initializers = ...)
. Documentation in Spring Reference Manual.Regards,
Sam (author of the Spring TestContext Framework)