Error when trying to execute single test method with jUnit


(Larisa Grecu) #1

I am trying to run a single test method with gradlew test --tests *TestName.testMethod, but I have this error:

 What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [*TestName.testMethod]

What am I doing wrong?
Thank you!


(Chris Doré) #2

The only way I was able to reproduce your issue is if the test did not exist. I was able to get the same command as you working:

./gradlew test --tests *DemoLibTest.testMethod

$ cat src/test/groovy/com/example/demo/demo_lib/DemoLibSpec.groovy

package com.example.demo.demo_lib
import spock.lang.Specification
class DemoLibTest extends Specification {
    def demoLib
    def setup() {
        demoLib = new DemoLib()
    }
    def 'can greet a person'() {
        expect:
        demoLib.getGreeting( "Foo" ) == "Hello Foo, from DemoLib!"
    }
    def testMethod() {
        expect:
        true
    }
}

Was also able to get spock tests working where test names contain spaces:

./gradlew test --tests "*DemoLibTest.can\ greet\ a\ person"

Does it work if you specify a fully qualified test instead of using *? ie:

./gradlew test --tests the.test.class.package.TestName.testMethod

Can you post an example that reproduces the issue?
Also, which version of Gradle are you using? I tested in 2.3.