首页 > 解决方案 > Spring Boot 集成测试覆盖自定义 .properties 文件

问题描述

我正在实施集成测试,但在覆盖我的应用程序使用的自定义属性时遇到了问题。

集成测试样本:

@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;

将使用提供的应用程序@TestPropertySource(locations = "classpath:test.properties")覆盖application.properties我的应用程序

但是,我的应用程序使用这样的自定义属性文件:

@Configuration
@PropertySource("classpath:fileProvider/custom.properties")
@ConfigurationProperties(prefix = "com.sample.config")
public class SampleProviderConfigProperties {

在我的应用程序中有许多外部提供商。他们每个人都喜欢SampleProviderConfigProperties有自己的配置

在集成测试中,我想custom.properties用测试系统的配置替换提供者。

有没有办法做到这一点?

标签: javaspringspring-bootspring-testspring-boot-test

解决方案


推荐阅读