Selecting specific tests to run in gradle

Ray Nicholus picture Ray Nicholus · Apr 1, 2011 · Viewed 16.8k times · Source

I'm trying to fix our messy failing test runs, and, unfortunately, I'm very new to gradle. We currently have testng, junit, and I'd like to add some spock tests to the mix as well. I'm not quite sure how gradle determines which tests to run when I type "gradle test". How can I prevent the testng &/or junit tests from running? How can I get gradle to start running my spock tests?

Answer

Peter Niederwieser picture Peter Niederwieser · Apr 2, 2011

By default, the test task runs all JUnit tests it can find, which includes any Spock tests. To make it run TestNG tests instead, configure the task as follows:

test {
    useTestNG()
}

If you have both JUnit and TestNG tests, you need two test tasks, one for each test framework.

To run a subset of tests, use the -Dtest.single system property. For more information, see the corresponding section in the Gradle User Guide.