Note: Earlier Cucumber other implementation except Cucumber-JVM default to --non-strict mode. With version 6, Cucumber-JVM will default to --strict mode. More Information Here: Cucumber 6 default to --strict mode
Using the --strict flag will cause cucumber to fail unless all the step definitions have been defined.
Table of Contents
strict = false in cucumber
false: If strict option is set to false then at execution time if cucumber encounters any undefined/pending steps then cucumber does not fail the execution and undefined steps are skipped and BUILD is SUCCESSFUL and
strict = true in cucumber
true: if Strict option is set to true then at execution time if cucumber encounters any undefined/pending steps then cucumber does fails the execution and undefined steps are marked as fail and BUILD is FAILURE.
Cucumber Option Strict Example
package com.pb.cucumbertest.stepdefinitions;
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"},
strict = true
)
public class Runner {
}
- Method Signature: public abstract boolean strict
- Returns: true if strict mode is enabled (fail if there are undefined or pending steps)
- Default: false
Consider below feature file, Here step definition is defined with Given step and step definition is not defined with for When step.
Feature: Search Feature
@mysearch
Scenario: Title of your scenario
Given I am on the home page
When I fill in "search" with "xyz"
Output in JUnit section when Strict is true
io.cucumber.junit.UndefinedThrowable: The step "I fill in "search" with "xyz"" is undefined
Output when Strict is false
You will see when strict is set to false, even when step does not exist; it will not throw any error.