问题描述
我需要为我的JUnit测试定义一个系统属性。我已经尝试了各种步骤将名称/值对传递给gradle。 (我试过Milestone-3和4)。
这些方法都不起作用:
I need to define a system property for my JUnit tests. I've tried various steps to pass the name/value pair into gradle. (I've tried Milestone-3 and 4).None of these approaches worked:
- 在gradle.properties文件中定义systemProp.foo = bar
- 在命令行传递-Dfoo = bar
- 传递-PsystemProp.foo =命令行上的bar
尽管我不确定我应该怎么做,但我没有看到来自gradle properties的附加属性。但更重要的是,我将System.properties转储到静态初始化器中,并且该属性不在那里。我需要将System属性传递给正在运行的测试,以告诉它们它们正在运行的环境(本地,Jenkins等)。
I don't see the additional properties from "gradle properties" though I'm not sure I should. But more importantly, I dumped the System.properties in a static initializer and the property is not there. I need to pass System properties to the running tests to tell them what environment (local, Jenkins, etc) they are running in.
推荐答案
此处的解决方案:
test {
systemProperties = System.properties
}
test {systemProperties = System.properties}
这篇关于如何在JUnit Test Execution期间添加Java系统属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!