Skip to content

Keywords : Strict keyword enforcement  #1392

@Auto81

Description

@Auto81

Summary

Not a bug, but a functionality query/request. Is there a way to enforce using the same keyword, from the stepDef in scenario?

I have read the gherkin docs and only thing I can see related to this is 'This might seem like a limitation, but it * forces * you to come up with a less ambiguous, more clear domain language'.

Which, with the following example, can also allow for nonsense scenarios to sneak through.

Current Behaviour (java example)

Only one Step Def exists

@Given("^I am not allowed '{food}'$")
public void addDeadlyFood(Food food) {
    deadlyFoods.add(food);
}

Will allow for the following scenario to be written and run, where no asserts actually happen. A list of deadly foods just gets added to, but never checked.

Scenario: Ambiguous Steps
  Given I am not allowed 'Apples'
  And   I am not allowed 'Bananas'
  Then  I am not allowed 'Apple Tart'
  And   I am not allowed 'Banana Bread'

Possible Solution

Have a cucumber option along the lines of 'respectKeywordDefinition : true'. This would flag the 3rd and 4th step as undefined, which would be more helpful at highlighting that another stepDef needs to be created. This would then actually * force * a new step to be created, with a less ambiguous, more clear domain language. eg,

@Then("^I am not allowed to eat '{food}'$")
public void checkForDeadlyFood(Food food) {
    Assert.false(allowedToEat(food));
}
Scenario: Unambiguous Steps
  Given I am not allowed 'Apples'
  And   I am not allowed 'Bananas'
  Then  I am not allowed to eat 'Apple Tart'
  And   I am not allowed to eat 'Banana Bread'

Context & Motivation

Motivation has come about due to it being very easy for scenario to be written with steps that don't actually exist. Which then looks like a genuine test scenario, but nothing is actually being tested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions