Askar Ibragimov Askar Ibragimov - 1 year ago 142
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?

Answer Source


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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download