I am new to Gradle. I use Gradle 1.10 and Ubuntu 13.
I want to know if there's any command to execute only one unit test class, similar to testOnly
in SBT.
If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”. As the output shows, only the test class we've passed to the test parameter is executed.
To run a single test class Airborn's answer is good.
With using some command line options, which found here, you can simply do something like this.
gradle test --tests org.gradle.SomeTest.someSpecificFeature gradle test --tests *SomeTest.someSpecificFeature gradle test --tests *SomeSpecificTest gradle test --tests all.in.specific.package* gradle test --tests *IntegTest gradle test --tests *IntegTest*ui* gradle test --tests *IntegTest.singleMethod gradle someTestTask --tests *UiTest someOtherTestTask --tests *WebTest*ui
From version 1.10 of gradle it supports selecting tests, using a test filter. For example,
apply plugin: 'java' test { filter { //specific test method includeTestsMatching "org.gradle.SomeTest.someSpecificFeature" //specific test method, use wildcard for packages includeTestsMatching "*SomeTest.someSpecificFeature" //specific test class includeTestsMatching "org.gradle.SomeTest" //specific test class, wildcard for packages includeTestsMatching "*.SomeTest" //all classes in package, recursively includeTestsMatching "com.gradle.tooling.*" //all integration tests, by naming convention includeTestsMatching "*IntegTest" //only ui tests from integration tests, by some naming convention includeTestsMatching "*IntegTest*ui" } }
For multi-flavor environments (a common use-case for Android), check this answer, as the --tests
argument will be unsupported and you'll get an error.
In versions of Gradle prior to 5, the test.single
system property can be used to specify a single test.
You can do gradle -Dtest.single=ClassUnderTestTest test
if you want to test single class or use regexp like gradle -Dtest.single=ClassName*Test test
you can find more examples of filtering classes for tests under this link.
Gradle 5 removed this option, as it was superseded by test filtering using the --tests
command line option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With