Answer
@CucumberOptions Annotation
@CucumberOptions annotation is used on the TestRunner class to configure how Cucumber executes tests. It provides a link between feature files and step definitions, and configures plugins, tags, and execution behavior.
Syntax
Java
@CucumberOptions(
features = "src/test/resources/features",
glue = {"stepDefinitions", "hooks"},
plugin = {"pretty", "html:target/cucumber-reports/report.html", "json:target/cucumber.json"},
tags = "@smoke",
dryRun = false,
monochrome = true
)
All Available Options
| Option | Purpose | Example |
|---|---|---|
features | Path to feature files | "src/test/resources/features" |
glue | Package(s) of step definitions | {"stepDefs", "hooks"} |
plugin | Reporting format and output | "html:target/report.html" |
tags | Filter which scenarios to run | "@smoke and not @slow" |
dryRun | Check for missing step defs | true / false |
monochrome | Clean console output | true |
name | Filter by scenario name regex | "Login.*" |
publish | Publish report to Cucumber Cloud | true |
Complete TestRunner Example
Java
package runners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
@CucumberOptions(
features = "src/test/resources/features",
glue = {"stepDefinitions", "hooks"},
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber.html",
"json:target/cucumber-reports/cucumber.json",
"junit:target/cucumber-reports/cucumber.xml"
},
tags = "@smoke",
dryRun = false,
monochrome = true
)
public class TestRunner extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
dryRun = true
When dryRun = true, Cucumber checks if all steps in feature files have corresponding step definitions without actually executing the tests. Use this to detect missing step definitions.
Syntax of @CucumberOptions Tag
CODE
@CucumberOptions(features="Features", glue={"StepDefinition"})
