How to run acceptance tests (with TestNG) from gradle?

Hi

I’m new to Gradle (and Groovy).

I have a gradle java project, containing acceptance tests (for a system under test running on a specific target hardware). The acceptance tests are written in Java using TestNG as the test engine. For example, I have a project structure something like this:

src/main/java --com.company.tests ----- MyFirstAcceptanceTest.java

src/main/resources --testng.xml

src/test/java --com.company ----- SomeUnitTest.java

How can I configure the gradle build script to run the testng.xml file? Eventually I would like to have the testng.xml executed my the Gradle plugin in Jenkins.

Note! I don’t want to run the Unit tests in this stage (as that should be taken care of elsewhere). I want to run the tests pointed out by the testng.xml.

I have googled and looked at these gradle documentations: * http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.testing.Test.html * http://gradleware.com/registered/books/building-and-testing/testing.html#_testng * http://www.gradle.org/docs/current/groovydoc/org/gradle/api/tasks/testing/testng/TestNGOptions.html but could not find any working examples :frowning:

Further on, I might add more testng suites under “src/main/resources”, is there a way to tell gradle wich testng suite to choose (preferably from Jenkins or command line).

I’m using: $ gradle -v

------------------------------------------------------------ Gradle 2.1 ------------------------------------------------------------ Build time:

2014-09-08 10:40:39 UTC Build number: none Revision:

e6cf70745ac11fa943e19294d19a2c527a669a53 Groovy:

2.3.6 Ant:

Apache Ant™ version 1.9.3 compiled on December 23 2013 JVM:

1.8.0_11 (Oracle Corporation 25.11-b03) OS:

Windows 7 6.1 amd64

Thanks in advance, Alex

You can specify which testng suites to execute in a test task using the following:

test {
     useTestNG {
         suites 'src/main/resources/testng.xml'
     }
 }