Dry Run in Cucumber

Dry Run in Cucumber

Table of Contents

  1. What is Dry Run in Cucumber
  2. Cucumber Dry Run Method Signature
  3. Dry Run Example
  4. Dry Run False in Cucumber
  5. Dry Run True in Cucumber
  6. Video Tutorial

What is Dry Run in Cucumber?

Dry Run allows you to quickly check your feature's steps without running the code inside their associated step definitions to ensure that every Step has the corresponding Step Definition available in the Step Definition file. A cucumber dry run is used to compile the Step Definition and Feature files and verify the compilation errors.

Cucumber Dry Run Method Signature

The Dry Run parameter is a part of the @CucumberOptions, which is used to configure the test settings. The Dry Run option can either be set as true or false. 

  • Method Signature: public abstract boolean dryRun
  • Returns: true if this is a dry run
  • Default: false

Dry Run Example

Runner Class

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
		plugin = {"pretty", "html:target/cucumber"},
		features = {"features"},
		glue={"com.pb.cucumbertest.stepdefinitions"},
		monochrome = true,
		strict = true,
		dryRun = true
		)

public class Runner {

}

Feature File

@MyTag
Feature: Title of your feature

Scenario: Title of test scenario
  Given I am on the home page 
  Then I follow "Ask Doubt" 
  When I should see Ask Doubt page

Here, Step 1 is correct, Step 2 has incorrect locator and Step 3 has missing step definition.

Dry Run False in Cucumber

Your browser will open and all statements inside the step definitions method will execute when set to false.

Dry Run False in Cucumber

Take a look at the time duration (37 seconds) now at the end of every Step. You will find that it is comparatively higher when Dry Run is True. That is because the code inside all step definitions is executed.

Also, note that it failed at step 2 with NoSuchElementExecption and stopped the execution and didn't jump to Step 3.

Dry Run True in Cucumber

Dry Run True in Cucumber

Take a look at the time duration at the end of every Step. It is extremely less. None of the Steps is executed, but Cucumber has only made sure that every Step has the interconnected method available in the Step Definition file.  

Your browser will not open in this case, Cucumber will just check that every Step mentioned in the Feature File has an affiliated method written in the Step Definition file or not. So in case any of the methods is missed in the Step Definition for any Step in Feature File, it will give us the message.

Here, code inside the step definition method will not execute. You can observe that Step 2 is not failed, and it jumps to Step 3 and returns that Step Definition is missing, and you can implement the missing Step.

So, you can set dry run to true to quickly check if any of the step definition is not implemented.

Video Tutorial: Cucumber Dry Run Option

Managed ad


Tarun Goswami
Tarun possesses over 12+ years of extensive expertise in software testing and automation utilizing diverse JavaScript and Java technologies. Concurrently, he has dedicated his free time to crafting insightful blogs within the field.