Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Gradle runs no Cucumber scenarios from my feature files

Errorgradle test finishes successfully but no Cucumber scenarios are listed

Short answer

Cucumber runs on the JUnit Platform, so Gradle must call useJUnitPlatform() and have the cucumber-junit-platform-engine on the test classpath. Also check that Gradle can see the feature directory, that cucumber.features is not overriding your selectors, and that the test task is not skipped as up to date.

  • Applies to Gradle 8.x and 9.x, Cucumber-JVM 7 and later, JUnit Platform, Java 17 and 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Force the test task to run again and read its output. This separates a skipped task from one that really finds nothing.

    ./gradlew test --rerun
  2. 2Match what you see, then jump to its fix

    1. 1The task finishes with no Cucumber output at allThe test task does not use JUnit Platform, or has no Cucumber engineFix
    2. 2Engine is present, but resource-based tests are never foundGradle is not pointed at the feature filesFix
    3. 3A suite class with @SelectPackages runs nothing, and cucumber.features is set in properties or the command linecucumber.features overrides every other selectorFix
    4. 4The console shows the test task as UP-TO-DATEGradle skipped the test task as up to dateFix

What does the error look like?

  • gradle test finishes successfully but no Cucumber scenarios are listed
  • Feature files exist under src/test but nothing runs

Cause 1 of 4

The test task does not use JUnit Platform, or has no Cucumber engine

1Check

Cucumber discovery is done by the cucumber engine. The README says to add cucumber-junit-platform-engine (and junit-platform-suite for suites) and, for Gradle, to enable useJUnitPlatform().

./gradlew dependencies --configuration testRuntimeClasspath | grep -i cucumber

2Fix

Add the engine and select the platform. Take the version from the Cucumber BOM.

// build.gradle.kts
dependencies {
    testImplementation("io.cucumber:cucumber-junit-platform-engine")
}
tasks.named<Test>("test") {
    useJUnitPlatform()
}

3Verify

Run the tests; scenarios should now be listed.

./gradlew test --rerun

Confirmed by github.com

Did this fix it?

Cause 2 of 4

Gradle is not pointed at the feature files

1Check

Gradle supports resource-based tests, and the README points the test task at the directory holding the .feature files.

find . -name "*.feature" -not -path "*/build/*"

2Fix

Declare the feature directory on the test task.

tasks.named<Test>("test") {
    useJUnitPlatform()
    testDefinitionDirs.from("src/test/features")
}

3Verify

Run again and check the report.

./gradlew test --rerun

Confirmed by github.com

Did this fix it?

Cause 3 of 4

cucumber.features overrides every other selector

1Check

The README warns that setting cucumber.features makes Cucumber ignore other selectors, such as those on a suite class.

grep -rn "cucumber.features" src/ build.gradle* gradle.properties

2Fix

Remove the property, or put the right path in it deliberately. Remember that cucumber.glue takes comma separated package names.

# src/test/resources/cucumber.properties
cucumber.glue=com.example

3Verify

Run the suite again.

./gradlew test --rerun

Confirmed by github.com

Did this fix it?

Cause 4 of 4

Gradle skipped the test task as up to date

1Check

Gradle does not rerun tests whose inputs did not change.

./gradlew test

2Fix

Force a rerun.

./gradlew test --rerun

3Verify

The task shows as executed and prints results.

./gradlew test --rerun

Confirmed by docs.gradle.org

Did this fix it?

How do I stop it coming back?

  • Keep the feature files and the glue package in one documented place.
  • Prefer cucumber.properties over scattered system properties.
  • Run tests with --rerun after changing only feature files if results look stale.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.