Search code examples
javagradlecucumberjunit5cucumber-junit

Selecting a single test with Cucumber JUnit5 engine fails


Consider this simple project: https://github.com/ekalin/cucumber-junit5-gradle. It contains a Cucumber feature, using JUnit5.

Following the instruction from https://github.com/cucumber/cucumber-jvm/tree/master/junit-platform-engine, I’ve created a class anotated with @Cucumber so that tests can be discovered. And when I run ./gradlew test, the feature is discovered and run.

But if I try to select only that test with ./gradlew test --tests cucumber.junit5.gradle.SampleSteps (or with other ways to select the test), I get this error:

Execution failed for task ':test'.
> No tests found for given includes: [cucumber.junit5.gradle.SampleSteps](--tests filter)

I’ve tried adding includeEngines("cucumber") to useJUnitPlatform but it didn’t make any difference.

Is there some configuration to allow selecting a single test when it’s using a different engine?


Solution

  • Gradle does not yet support discovery or filtering of non-class based tests (see: gradle/#4773). Instead Gradle asks the JUnit Platform to discover tests in all classes in the test package. The @Cucumber annotation is a work around to discover all feature files in the package of the annotated class.

    When you use --tests cucumber.junit5.gradle.SampleSteps you apply a class based filter on all test results. Because the @Cucumber annotated class is a work around it is not part of the discovered tests and because feature files do not have a ClassSource but rather a FileSource gradle will exclude them all.

    The best thing you can currently do is use the work around suggested in gradle/#4773. You may also want to request the Gradle team to provide a better integration with the JUnit Platform so all its feature can be used.