【发布时间】:2019-02-20 12:22:36
【问题描述】:
我正在尝试使用 application.properties 配置文件进行使用 JUnit 的集成测试,以检查两个不同的平台。
我尝试使用包含两个平台的通用配置的基本配置文件application.properties 这样做,除此之外,我还为每个平台添加了属性文件application-tensorflow.properties application-caffe.properties,它们具有特定的平台配置,但我发现它在 JUnit 中的工作方式与我在主应用程序中使用的方法不同。
我的测试配置类如下所示:
@Configuration
@PropertySource("classpath:application.properties")
@CompileStatic
@EnableConfigurationProperties
class TestConfig {...}
我正在使用@PropertySource("classpath:application.properties"),所以它会识别我的基本配置,在那里我还写了spring.profiles.active=tensorflow,希望它能识别张量流应用程序配置文件,但它不会从文件中读取:/src/test/resources/application-tensorflow.properties,也不像在主应用程序中那样来自/src/main/resources/application-tensorflow.properties。
在 JUnit 测试中是否有特殊的方法来指定弹簧配置文件?实现我想要做的事情的最佳实践是什么?
【问题讨论】:
标签: java spring spring-boot junit integration-testing