gpt4 book ai didi

groovy - 使用参数化 Junit 测试中的命令行参数或系统属性?

转载 作者:行者123 更新时间:2023-12-02 09:43:18 27 4
gpt4 key购买 nike

我使用此方法来设置我的参数化数据:

@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 test 使用 gradle 调用主测试,但我似乎看不到系统属性。

如果我使用调用 gradle -Dfile=test.story,则 System.getProperty('file') 未定义。如何将参数传递给此参数化数据生成器?

最佳答案

Gradle 在单独的 JVM 中运行所有测试。您必须配置 test 任务:

test {
systemProperty "file", "test.story"
}

有关详细信息,请参阅Gradle DSL reference .

关于groovy - 使用参数化 Junit 测试中的命令行参数或系统属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8855296/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com