[英]How can I override a property in an integration test from the command line in a gradle project?
Say, for example, you have a data source specified in a properties file and you want to override it in CI. 例如,假设您在属性文件中指定了数据源,并且希望在CI中覆盖它。 If I do something like:
如果我这样做:
gradle -DdataSource.user=fred clean integrationTest
...will this be visible to the running JVM of the test or will this go only to Gradle? ...这对于正在运行的测试JVM是可见的,还是仅仅是Gradle? What's the right way to do this?
这样做的正确方法是什么? I'm actually writing a test right now to figure this out, but somebody else can have the cheddar if the answer shows up here first.
我现在正在编写一个测试来解决这个问题,但是如果答案首先出现在这里,其他人可以拥有切达干酪。
No, just passing it this way won't make this variable avalable in your tests. 不,只是以这种方式传递它不会使这个变量在你的测试中有用。 You have configure your test tasks to make them populate this property into tests.
您已配置测试任务以使其将此属性填充到测试中。
This could be done once for all the test tasks this way 这可以通过这种方式对所有测试任务执行一次
tasks.withType(Test) { systemProperty 'datasource.user', System.getProperty('datasource.user', 'defaultisername') }
Or if you have a number of variable to populate, then pass them all once, like so 或者,如果要填充一些变量,则将它们全部传递一次,就像这样
test {
options {
systemProperties(System.getProperties())
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.