Answer
dryRun in Cucumber
What It Does
When dryRun = true, Cucumber:
- ✓Reads all
.featurefiles - ✓Tries to match each step to a step definition method
- ✓Reports any undefined or ambiguous steps
- ✓Does NOT execute any actual test code
Enable dryRun
Java
@CucumberOptions(
features = "src/test/resources/features",
glue = {"stepDefinitions"},
dryRun = true // ← enable dry run
)
public class DryRunRunner extends AbstractTestNGCucumberTests {}
When to Use dryRun
| Situation | Use dryRun? |
|---|---|
| Just wrote new feature files | Yes — check all steps are defined |
| Onboarding new feature area | Yes — verify step coverage |
| Refactored step definition text | Yes — ensure nothing broke |
| Normal CI regression run | No |
| Debugging a specific test failure | No |
dryRun Output Example
CODE
Undefined scenarios:
src/test/resources/features/payment.feature:15 # Pay with PayPal
Undefined step definitions:
@Given("the user selects PayPal as payment method")
public void theUserSelectsPayPal() {
// Write code here
throw new io.cucumber.java.PendingException();
}
Cucumber even generates the skeleton method for missing steps.
dryRun vs Normal Run Comparison
CODE
dryRun = true:
✓ Finds undefined steps (no step definition found)
✓ Finds ambiguous steps (multiple step definitions match)
✓ Fast — no browser, no network, no WebDriver
✗ Does NOT validate step logic
✗ Does NOT confirm test passes
dryRun = false (normal):
✓ Executes every step
✓ Validates actual application behavior
✗ Takes full execution time
✗ Requires browser/app
Common Workflow
Bash
# Step 1: Write feature files
# Step 2: dryRun to find what step defs are needed
mvn test -Pcucumber-dryrun
# Step 3: Write step definitions for undefined steps
# Step 4: dryRun again to confirm all steps are defined
# Step 5: Normal run
mvn test
Maven Profile for dryRun
XML
<profiles>
<profile>
<id>cucumber-dryrun</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<cucumber.options>--dry-run</cucumber.options>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
