How to give System property to my test via Gradle and -D

前端 未结 5 471
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 00:14

I have a a Java program which reads a System property

System.getProperty(\"cassandra.ip\");

and I have a Gradle build file that I start wit

5条回答
  •  误落风尘
    2020-11-29 00:39

    Here's a variant that passes numerous project properties to the test JVM as system properties. I prefer project properties over system properties to increase flexibility.

    task intTest(type: Test) {
        systemProperties project.properties.subMap(["foo", "bar"])
    }
    

    Which may be passed on the command-line:

     $ gradle intTest -Pfoo=1 -Pbar=2
    

    And retrieved in your test:

    String foo = System.getProperty("foo");
    

提交回复
热议问题