onkami
onkami

Reputation: 9411

Run JUnit test with external parameter using gradle

I have a Gradle project, in which gradle test (from the Java plugin https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html) 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?

Upvotes: 2

Views: 2013

Answers (1)

lance-java
lance-java

Reputation: 27994

build.gradle

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

Upvotes: 4

Related Questions