使用参数化Junit测试的命令行参数或系统属性? [英] Using command line arguments or system properties from a Parameterized Junit test?
本文介绍了使用参数化Junit测试的命令行参数或系统属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此方法来设置我参数化的数据:
I use this method to setup my parameterized data:
@Parameterized.Parameters
public static Collection<Object[]> getStories() {
Collection<Object[]> allStories = new ArrayList<Object[]>()
new File(SPEC_DIRECTORY).eachFileRecurse(FileType.FILES) { file ->
if (file.getName().endsWith('.story')) {
Object[] args = [file.getName(), file]
allStories << args
}
}
return allStories
}
我使用gradle通过 gradle test
调用主测试,但我似乎无法看到系统属性。
I invoke the main test with gradle via gradle test
, but I do not seem to be able to see system properties.
如果我使用调用 gradle这个-Dfile = test.story
,然后 System.getProperty( '文件')
未定义。如何将参数传递给此参数化数据构建器?
If I use the invocation gradle -Dfile=test.story
, then System.getProperty('file')
is undefined. How can I pass arguments to this parameterized data builder?
推荐答案
Gradle在单独的JVM中运行所有测试。您必须配置 test
任务:
Gradle runs all tests in a separate JVM. You have to configure the test
task:
test {
systemProperty "file", "test.story"
}
有关更多信息,请参阅 Gradle DSL参考资料。
For more information, see the Gradle DSL reference.
这篇关于使用参数化Junit测试的命令行参数或系统属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文