Askar Ibragimov Askar Ibragimov - 10 months ago 64
Java Question

Run JUnit test with external parameter using gradle

I have a Gradle project, in which gradle test (from the Java plugin would run JUnit tests.

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.

How I could pass to my test a certain string?



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