Gherkin keywords

Cucumber's Gherkin, like YAML and Python, is a line-oriented programming language where each line is a step, which begins with a keyword. This offers a simple and straightforward way for writing tests by structuring them into plain language statements. BDDX uses Gherkin and its keywords (in particular step keywords) for its BDD testing process.


Given is the first basic step which outlines the inintial stage and serves as a precondition. The purpose of Given steps is to put the system in a known state beofre the user starts interacting with it via the other steps. Tests can have several Given steps, usually included via the use of And or But to make things easie to read.


  • Given There is a tool to display test content
  • Given register functionality exists


When describes event or actions, for example those made by the user. You should only use a single When step per scenario and if you feel like you need more, it usually simply means you need to break up the scenario into multiple parts.


  • When user interacts with this tool
  • When user interacts with this tool by testing the functionality for errors


Just like When steps describe events, Then steps describe an expected outcome of that event. This step describes what should happen as a result of the action and should be flagged as an error if it does not.


  • Then test login.feature should be displayed
  • Then user should be able to reject this test's result

And & But

And & But are used to simply replace excessive uses Given, When and Then and make things more transparent. Its purely a stylistical choice and you can use repeated keywords if that's your preference.


  • Given /userHandling path exists
  • And login.feature exists
  • And there is a tool to display test content
  • When user interacts with this tool
  • Then test login.feature should be displayed
  • And after passing or failing, the next test from the selected path should be displayed
  • And if this is the last test or there was only a single test in the path, program should quit
  • But If path does not exist or there is a typo, then the proper error message should be displayed

Remember that setting up BDD tests properly and ensuring they are clear to understand is essential not for yourself, but for your testers.

Behavior driven testing CLI