Cucumber JVM JUnit 4 runner deprecation and JUnit 5 platform engine migration
0 reputation · 16 Sept 2025, 00:29 UTC
0 reputation · 16 Sept 2025, 00:29 UTC
A Cucumber JVM test suite is being upgraded from version 6.x to 7.x. The goal is to keep existing feature files and step definitions running while moving off the deprecated JUnit 4 runner. Cucumber JVM 7.x assumes Java 11 or higher and marks `cucumber-junit` as deprecated in favor of `cucumber-junit-platform-engine`.
It is unclear whether the JUnit 5 engine requires a corresponding JUnit Platform launcher configuration, how existing `@RunWith(Cucumber.class)` classes should be replaced, and whether tag expressions behave identically under the new engine. The project must also confirm that the runtime environment meets the Java 11 minimum before changing dependencies.
Which dependencies replace `cucumber-junit` in Cucumber JVM 7.x? Does the JUnit 5 platform engine support the same runner annotations and tag expressions? What configuration changes are required to run scenarios through JUnit Platform instead of JUnit 4?
35275 reputation · 16 Sept 2025, 04:46 UTC
Replace cucumber-junit with cucumber-junit-platform-engine (groupId io.cucumber), keep cucumber-java or cucumber-java8 for step definitions, and confirm your runtime is Java 11 or higher before upgrading. The JUnit 5 engine does not recognize @RunWith(Cucumber.class); instead you annotate a class with @Cucumber (or @ExtendWith(CucumberExtension.class)) and let the JUnit Platform discover feature files. Tag expressions remain compatible: continue using the same syntax via cucumber.filter.tags in cucumber.properties, @CucumberOptions, or the JUnit Platform launcher.
Remove the deprecated cucumber-junit artifact and add the platform engine. If you use Maven Surefire or Failsafe, version 2.22.2 or newer is required so the plugin can detect and launch the JUnit Platform engine automatically. If your project runs tests through a custom launcher or an older plugin, add junit-platform-suite-engine and create a @Suite class annotated with @SelectPackages to bootstrap discovery.
JUnit 4 runner classes annotated with @RunWith(Cucumber.class) should be replaced. The platform engine does not support that annotation. A minimal replacement looks like this:
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class CucumberTest {
}
Assuming a standard classpath layout, feature files are discovered from the classpath root by default. If your features live in a non-standard location, configure the glue or feature path through cucumber.properties or the @CucumberOptions annotation on the suite class.
Tag expression behavior is preserved. The same expressions that worked with the JUnit 4 runner continue to work. You can set them in cucumber.properties with cucumber.filter.tags=@smoke and not @wip, pass them through the existing @CucumberOptions tags attribute, or use the JUnit Platform console launcher option --select-tag. No syntax changes are required.
java -version and confirm the output reports 11 or higher.cucumber-junit from your dependency declarations and ensure it is not pulled in transitively.cucumber-junit-platform-engine and verify your build plugin supports JUnit 5.mvn test or gradle test and check the output for JUnit Platform engine discovery.-Dcucumber.filter.tags=@smoke) and confirm only matching scenarios execute.One diagnostic detail would change the recommendation: if your CI or IDE still launches tests through the old JUnit 4 @RunWith mechanism, you must update the test runner configuration before removing the old artifact, otherwise discovery will fail.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.