10

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.

Szymon Stepniak
  • 40,216
  • 10
  • 104
  • 131
eastwater
  • 4,624
  • 9
  • 49
  • 118
  • Possible duplicate of [How to run only one test class on gradle](https://stackoverflow.com/questions/22505533/how-to-run-only-one-test-class-on-gradle) 1st answer also includes how to run only one method. – tkruse Jan 08 '18 at 01:57

1 Answers1

14

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.

Szymon Stepniak
  • 40,216
  • 10
  • 104
  • 131
  • I tried gradle 4.0, 4.2 and gradle 4.4.1 as indicated in your link. It did not work. Execution failed for task ':test'. > No tests found for given includes: [example.TestFoo.testMethod1](--tests filter). thanks. – eastwater Jan 09 '18 at 01:32
  • @Sunnyday Double check if `example.TestFoo` is present in `src/test/java/example/` folder (or `src/test/groovy/example/` is you use Groovy for testing). Also check if running `gradle test -tests example.TestFoo` works - if not, then there is a problem with loading test class. – Szymon Stepniak Jan 09 '18 at 07:56
  • It is parameterized test. example.TestFoo.testMethod1[0] works. Thanks. – eastwater Jan 09 '18 at 18:40
  • 3
    shouldn't it be --tests instead of -tests? – garnet Feb 27 '19 at 14:41