【发布时间】:2017-11-22 05:21:47
【问题描述】:
对于我的一个 Spring bean(比如应用程序类),我使用 @Value 注释从属性文件(prop.properties)中获取属性的值(my.property.flag=true/false)。效果很好。
我需要编写一个集成测试(比如 ApplicationIt 类),我需要在其中测试属性的值,即真假。
在我的属性文件中,属性的值设置为 true。是否可以从我的集成测试中将值动态设置为 false?
例如,
prop.properties:
my.property.flag=true
应用类文件:
@Component
class Application {
//This value is fetched from properties file
//the value is set to true.
@Value(${my.property.flag})
private String isTrue;
......
..........
}
集成测试:
class ApplicationIT {
//how can I set the value of isTrue here to false?
}
【问题讨论】:
-
您可以使用测试覆盖创建单独的属性文件。
-
此属性文件中有许多属性,而我的要求仅适用于单个属性。我认为仅仅为这个单一的属性创建一个新的属性文件是不够明智的。
标签: java spring integration-testing spring-test