Gradle: Howto run testng suite with specified program argument

I am converting an ant project to gradle. The project uses a run configuration that specifies a testng suite XML file and a program argument “-master somefile.properties” to specify properties needed by the testing controller to run an automated acceptance test on a remote testing slave program. Curently I am specifying a task of type Test with a useTestNg() property like this:

task testSmoke (type: Test) {
     useTestNG {
         suites 'src/testsuites/smoketest/SmokeTestSuite.xml'
     }
}

This gets the suite to run but without the “-master somefile.properties” program argument in eclipse run configuration.

How can I specify the program argument to my testng controller that runs the suite. Thanks for an example.

you can pass program arguments to the test task

test {
    ...
    jvmArgs '-master', 'somefile.properties'
}

does that solve your issue?

The suggestion to use jvmArgs sends the args to the JVM which says:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: -master
Could not write standard input into: Gradle Test Executor 1.
java.io.IOException: The pipe is being closed
	at java.io.FileOutputStream.writeBytes(Native Method)
	at java.io.FileOutputStream.write(FileOutputStream.java:345)
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
	at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
	at org.gradle.process.internal.streams.ExecOutputHandleRunner.run(ExecOutputHandleRunner.java:56)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)

I need to supply these arguments to the main class that is run by the testng harness for gradle. I am not sure what that is and how to do that.

Thanks for your help.

I think this would require a patch to the [TestNGTestClassProcessor] (https://github.com/gradle/gradle/blob/f24146cc5f956a1b03a515bbee4225e6f861b6ab/subprojects/testing-jvm/src/main/java/org/gradle/api/internal/tasks/testing/testng/TestNGTestClassProcessor.java#L89) so that it supports invoking TestNG.setMaster(String)

That is what I was looking at too. Can you tell me how to specify that in gradle? TIA!

My guess is that it will require fix in an upcoming gradle release.

As a workaround you could use [gradle’s ant support] (https://docs.gradle.org/current/userguide/ant.html) to invoke the testng ant task instead of using gradle’s testng integration.

farrukhnajmi: Did you ever solve this?

I’m trying to setup a master/slave with ant and TestNG, how did you do it with ant?