</>

Technology

Cucumber

Difficulty

Intermediate

Interview Question

What is dryRun in Cucumber and when should you use it?

Answer

dryRun in Cucumber

What It Does

When dryRun = true, Cucumber:

  1. Reads all .feature files
  2. Tries to match each step to a step definition method
  3. Reports any undefined or ambiguous steps
  4. 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

SituationUse dryRun?
Just wrote new feature filesYes — check all steps are defined
Onboarding new feature areaYes — verify step coverage
Refactored step definition textYes — ensure nothing broke
Normal CI regression runNo
Debugging a specific test failureNo

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>

Follow AutomateQA

Related Topics