Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle test: how to run one method?

Tags:

gradle

testing

How to run just one method of a test case for debugging with Gradle? I have tried:

gradle test -tests example.TestFoo#testMethod1 --debug-jvm

but it ends up with following error:

No tests found for given includes: example.TestFoo#testMethod1

The test TestFoo class has testMethod1(), testMethod2(), etc.

like image 229
eastwater Avatar asked Jan 07 '18 23:01

eastwater


People also ask

How do I run a specific test in Gradle?

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.

How do I skip a specific test in Gradle?

Using Command Line Flags Task :compileTestJava > Task :processTestResources NO-SOURCE > Task :testClasses > Task :test > ... To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build.


1 Answers

Use . instead # in your tests filter expression to point to a method name:

gradle test --tests example.TestFoo.testMethod1 --debug-jvm

You can find more examples on filtering tests in 48.14.3. Test filtering documentation section.

like image 160
Szymon Stepniak Avatar answered Dec 16 '22 20:12

Szymon Stepniak