Tuesday, July 31, 2018

About Gherkin Keywords

Gherkin is a structured natural language that is used by business analysts to specify how they want the system to behave for given scenarios. The Gherkin language is simple.  It uses about 10 keywords (Given, When, Then, And, But, Scenario, Feature, Background, Scenario Outline, Examples) which allow the language to be read and parsed by an automation tool called Cucumber. Here is an example:

Feature: Some terse yet descriptive text of what is desired
  In order to realize a named business value
  As an explicit system actor
  I want to gain some beneficial outcome which furthers the goal

  Scenario: Some determinable business situation
    Given some precondition
      And some other precondition
     When some action by the actor
      And some other action
      And yet another action
     Then some testable outcome is achieved
      And something else we can check happens too


Gherkin has a few high-level benefits:

1) Business Friendly Language: Gherkin is a simple to understand language using a limited number of keywords.  It's simplicity and natural style make it easy for business people to read and understand.

2) Requirement Traceability: It's used to write acceptance tests with a focus on system behavior.  Each acceptance test links to a scenario and feature which allows it to be traced back to the original requirements.  This is particularly evident with Agile methods that use short user stories combined with acceptance tests to define the requirements.

3) Test Automation: As a structured language using keywords, Gherkins is machine readable with the automation tool called Cucumber.  Developers write executable code for each step of the Gherkin acceptance test resulting in fully automated test scenarios.

4) Team Communication: With such a strong focus on defining acceptance tests business analyst, QA, and developers find themselves working more closely together to define, build, and test their applications.  The Gherkin acceptance test becomes a powerful and precise communication tool.

Here is the list of keywords that Gherkin supports:

  • Feature - List of scenarios.
  • Background - List of steps run before each of the scenarios
  • Scenario - Business rules through the list of steps with arguments.
  • Given - Some precondition step
  • When - Some key actions
  • Then - To observe outcomes or validation
  • And - To enumerate more Given, When, Then steps
  • But - To enumerate more Given, When, Then steps
  • Examples - Container for s table
  • * - replacement of all other step/blue keys

No comments:

Post a Comment