Dry Run in Cucumber

Profile picture for user devraj
Submitted by devraj on

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 Options

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

Cucumber Options Dry Run Example

Runner Class

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

		plugin = {"pretty", "html:target/cucumber"},
		features = {"features"},
		monochrome = true,
		strict = true,
		dryRun = true

public class Runner {


Feature File

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.

JUnit Output when dryRun set to false

Cucumber Output when dryRun set to true

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

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.

JUnit Output when dryRun set to true

Cucumber Output when dryRun set to true

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: Dry Run in Cucumber