Udemy REST Assured free

Cucumber Options (@CucumberOptions) : Strict

Using the --strict flag will cause cucumber to fail unless all the step definitions have been defined. 

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

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.

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

Example of Cucumber Options: Strict

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

output when cucumber options strict is true

io.cucumber.junit.UndefinedThrowable: The step "I fill in "search" with "xyz"" is undefined

Output when Strict is false

cucumber options when strict is false

You can see when strict is set to false, even when step does not exist; it is not throwing any error.

Video Tutorial: How to use Strict option inside @CucumberOptions annotation