Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting specific tests to run in gradle

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?

like image 950
Ray Nicholus Avatar asked Apr 01 '11 16:04

Ray Nicholus


People also ask

How do I run all Gradle tests?

Run Gradle testsIn your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.


2 Answers

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.

like image 128
Peter Niederwieser Avatar answered Oct 12 '22 13:10

Peter Niederwieser


You may provide using the command line:

$> gradle test --tests org.somewhere.MyTestClass

Or even

$> gradle test --tests org.somewhere.MyTestClass.my_test_case
like image 41
Kier GRAY Avatar answered Oct 12 '22 12:10

Kier GRAY