Here is something that worked for me
//in build.gradle file
tasks.withType(Test) {
systemProperties = [
ip: System.getProperty('ip', '192.168.33.13'),
]
}
task integrationTests(type: Test){
useTestNG()
}
Suppose if you are using TestNG, you can add the annotation @Parameters as shown below
public class IpAddress {
@Test
@Parameters("ip")
public void printIpAddress(String ip) {
System.out.println(ip);
}
}
Now you are good to execute a gradlew command
./gradlew clean -Dip="xx.xx.xx.xx" integrationTests --tests "IpAddress"
If you want to use @DataProvider to pass the test data, you can pass it like below and execute the same above gradle command to run the test
public class IpAddress {
@DataProvider(name = "GetIP")
private static Object[][] getIp() {
return new Object[][]{
//if -Dip is not provided in command, then by default it gets the value assigned in build.gradle file i.e.'192.168.33.13'
{System.getProperty("ip")},
};
}
@Test(dataProvider = "GetIP")
public void printIpAddress(String ip) {
System.out.println(ip);
}
}
gradle -Dcassandra.ip=192.168.33.13
? Anyway, the test task forks one or several new JVMs. So you'll have to pass properties explicitely. Nobody forces you to hardcode their value in the build, though. – Smuts