Q19 of 21 · BDD / Cucumber
How do you configure Cucumber in a Java project, and what are the key @CucumberOptions settings?
BDD / CucumberMidbddcucumberjavajunitconfiguration
Short answer
Short answer: @CucumberOptions on the test runner class sets the feature file path, step definition package, plugin list (reporters), tags, and monochrome mode. JUnit 5 uses @Suite + @SelectClasspathResource instead.
Detail
JUnit 4 runner (still common in existing projects):
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = "com.example.stepdefs",
plugin = {
"pretty",
"html:target/cucumber-reports/report.html",
"json:target/cucumber-reports/cucumber.json",
"io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"
},
tags = "@smoke and not @wip",
monochrome = true,
dryRun = false
)
public class TestRunner {}
JUnit 5 + Cucumber 7 (current standard):
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example.stepdefs")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, json:target/cucumber.json")
@ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@smoke")
public class TestRunner {}
Key settings explained:
| Setting | Purpose |
|---|---|
features |
Path to .feature files |
glue |
Package containing step definitions and hooks |
plugin |
Reporters: pretty (console), html, json, Allure |
tags |
Tag expression to filter which scenarios run |
monochrome |
Removes ANSI colour from console output (readable in CI logs) |
dryRun |
Validates all steps have definitions without executing them — useful when writing new features |
Runtime tag override (CLI / Maven):
mvn test -Dcucumber.filter.tags="@regression and not @slow"
This overrides @CucumberOptions tags, letting CI pipelines use different tag sets without code changes.
// WHAT INTERVIEWERS LOOK FOR
The key @CucumberOptions fields and what each does. JUnit 5 equivalent. The dryRun flag and runtime CLI override are strong bonus details.