对于我的其中一个Spring bean(称为Application类),我从属性文件(prop.properties)中获取属性值(my.property.flag = true/false)使用@Value注释。这很好。在集成测试中重写@Value
我需要编写一个集成测试(比如说ApplicationIt类),在这里我需要测试属性的值,例如true和false。
在我的属性文件中,该属性的值设置为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?
}
您可以创建一个单独的属性与测试忽略文件将其更改为任何你想要的值。 – shmosel
此属性文件中有许多属性,并且我拥有的要求仅适用于单个属性。我不认为它足够明智地为这个单独的属性创建一个新的属性文件。 – Sandy
你可能要检查这个https://stackoverflow.com/questions/16478679/update-field-annotated-with-value-in-runtime –