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” 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” 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', ''

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. The pipe is being closed
	at Method)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(
	at org.gradle.internal.concurrent.StoppableExecutorImpl$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$

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] ( 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] ( 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?