Selecting specific tests to run in gradle
Asked Answered
R

3

14

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?

Rhoades answered 1/4, 2011 at 16:26 Comment(0)
P
15

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.

Prong answered 2/4, 2011 at 12:9 Comment(2)
I looked at the documentation you referenced, but it is quite confusing. For example, what on earth does: "gradle -Dtest.single=a/b/ test" mean? I'm trying to prevent standard junit tests from running, but run spock & testng tests. I'm not having any luck.Rhoades
From the documentation: The testNamePattern will be used to form an include pattern of **/testNamePattern*.class. Hence a/b/ selects all test classes below a package a.b. (Note that a doesn't necessarily have to be a root package.) To run Spock and TestNG but not JUnit tests, you'll need two tasks (as explained above), and configure the JUnit task to just include Spock tests (by package or class naming convention).Prong
B
8

You may provide using the command line:

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

Or even

$> gradle test --tests org.somewhere.MyTestClass.my_test_case
Bedight answered 8/8, 2016 at 9:21 Comment(0)
B
3
$> gradle test -Dtest.single=YourTestClass
Britishism answered 30/4, 2014 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.