[英]Does anyone know how to pass gradle properties to unit test and override them on command line?
For example, I would like to run smoke tests in Jenkins and the tests will use a different port/address depending on the environment. 例如,我想在詹金斯(Jenkins)中运行冒烟测试,并且测试将根据环境使用不同的端口/地址。 So I want to set a default value somewhere (gradle.build?) and then be able to override it on the gradle command line.
所以我想在某个地方设置默认值(gradle.build?),然后能够在gradle命令行上覆盖它。 But I need to use the default or overridden value in my junit test.
但是我需要在我的junit测试中使用默认值或覆盖值。 Right now I'm just reading a properties file in my junit test to get the url but I want to use it somehow from gradle.build value.
现在,我只是在junit测试中读取属性文件以获取url,但我想以某种方式从gradle.build值中使用它。
Right now I just use property file. 现在我只使用属性文件。
@Before
public void setup() throws FileNotFoundException, IOException{
try {
props.load(new FileInputStream("gradle.properties"));
} catch (IOException e) {
logger.error(e.getMessage());
logger.debug("Error loading gradle.properties",e);
}
}
@Test
public void testResponseCode () {
get(props.getProperty("url") + HISTORIC).then().assertThat().statusCode(equalTo(200));
}
You will probably need to pass it through Gradle as a system property, ie -Dkey=value
. 您可能需要将其作为系统属性通过 Gradle传递,即
-Dkey=value
。 Alternatively, your Gradle script could set a system property, eg System.properties.'my.property' = ?
另外,您的Gradle脚本可以设置系统属性,例如
System.properties.'my.property' = ?
. 。 A JUnit test will have no access to Gradle properties.
JUnit测试将无法访问Gradle属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.