Spring Boot Integration Tests override custom .properties file
Spring Boot Integration Tests override custom .properties file
I am implementing integration tests and I have a problem with overriding custom properties that my application use.
Integration test sample:
@RunWith(SpringRunner.class)
@SpringBootTest(
classes = Application.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
@TestPropertySource(locations = "classpath:test.properties")
public abstract class BaseIntegrationTest {
@Autowired
protected TestRestTemplate restClient;
The @TestPropertySource(locations = "classpath:test.properties") will override application.properties of my application with one that is provided
@TestPropertySource(locations = "classpath:test.properties")
application.properties
However, my application use custom property file like this:
@Configuration
@PropertySource("classpath:fileProvider/custom.properties")
@ConfigurationProperties(prefix = "com.sample.config")
public class SampleProviderConfigProperties {
In my application there is many external providers. Each of them like SampleProviderConfigProperties has with it's own configuration
SampleProviderConfigProperties
In integration tests I would like to replace the provider custom.properties with configuration for test systems.
custom.properties
Is there any way to achieve that ?
@Profile("test")
@Profile("custom")
Where you mean to add it. @SampleProviderConfigProperties is then injected in other bean
– Aleydin Karaimin
Jul 1 at 14:20
@TestPropertySource(locations= {"classpath:test.properties","classpath:testcustom.properties",....}) does this work for you?– Dirk Deyne
Jul 1 at 14:25
@TestPropertySource(locations= {"classpath:test.properties","classpath:testcustom.properties",....})
@DirkDeyne It worked, I am amazed, I don't know how. My application.properties is mapped to test.properties, but others are mapped with the same name.
– Aleydin Karaimin
Jul 1 at 14:38
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
have you tried to add
@Profile("test")or@Profile("custom")?– dehasi
Jul 1 at 14:05