[英]Run JUnit test with external parameter using gradle
I have a Gradle project, in which gradle test (from the Java plugin https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html ) would run JUnit tests. 我有一个Gradle项目,其中gradle测试 (来自Java插件https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html )将运行JUnit测试。
The test is using a network connection, and I need to pass to the test some hostname, parameter from command line of the test, preferably attached to gradle command line, or otherwise, editing build.gradle file. 该测试使用网络连接,我需要将一些主机名,测试命令行中的参数传递给测试,最好将其附加到gradle命令行中,否则,请编辑build.gradle文件。
How I could pass to my test a certain string? 如何将某个字符串传递给我的测试?
build.gradle build.gradle
apply plugin: 'java'
test {
systemProperty 'test.hostname', System.getProperty('test.hostname')
}
Test case 测试用例
Assert.assertEquals("foo", System.getProperty("test.hostname"));
Then from command line 然后从命令行
gradle test -Dtest.hostname=foo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.