Cucumber_Test_Runner_Plugins_with_JUnit5

Cucumber Test Runner Plugins with JUnit 5

One practical Cucumber Test Runner Plugins interview question is: How do you configure Cucumber Test Runner plugins with JUnit 5? The mechanics differ from the classic @CucumberOptions approach used with JUnit 4. With JUnit5, Cucumber is configured through the JUnit Platform Suite engine using @ConfigurationParameter.

Cucumber Test Runner Plugins

Cucumber plugins control what is generated during a test execution, including console output, test reports, and machine-readable results that can be consumed by CI/CD or other reporting tools.

With JUnit 5, you can configure Cucumber plugins directly on the @Suite class:

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(
key = GLUE_PROPERTY_NAME,
value = "com.rotebit.stepdefs"
)
@ConfigurationParameter(
key = PLUGIN_PROPERTY_NAME,
value = "pretty, "
+ "summary, "
+ "html:target/cucumber-reports/report.html, "
+ "json:target/cucumber-reports/report.json, "
+ "junit:target/cucumber-reports/report.xml, "
+ "rerun:target/rerun.txt"
)
public class RunCucumberTest {}

Here are some commonly used Cucumber plugins and why they are useful:

  • pretty – Provides readable console output during local development.
  • summary – Displays a compact pass/fail summary after execution.
  • html:path – Generates an HTML report that is easy to share with stakeholders.
  • json:path – Produces machine-readable results for custom dashboards and reporting integrations.
  • junit:path – Generates JUnit XML, which CI tools such as Jenkins, GitHub Actions, and Azure DevOps can process.
  • rerun:path – Records failed scenarios as file:line entries so they can be executed again.

Cucumber Dry Run with JUnit 5

Another common Cucumber interview question is: What is dry run, and how do you execute it with JUnit 5?

Dry run validates that Gherkin steps have matching and unambiguous step definitions without actually executing the scenarios. This means browsers are not launched and API calls are not performed.

With JUnit 5, you can enable it through a runtime configuration parameter:

mvn test -Dtest=RunCucumberTest -Dcucumber.execution.dry-run=true

This approach is particularly useful in CI/CD pipelines. You can run a fast validation stage before the actual test suite, without maintaining a separate runner class just for dry-run execution.

Interview Tip

A strong answer is to explain why each plugin is used rather than simply listing plugin names. Mentioning how JUnit XML supports CI reporting and how rerun helps isolate failed scenarios demonstrates practical Cucumber automation experience.

Related Links

Cucumber Interview Questions and Answers

Cucumber JUnit5 Test Runner Setup

Why most Cucumber Projects are not actually doing BDD


Discover more from Rotebit

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply