Creating a feature
In a previous post we explained What Is Gherkin and How Do You Write Gherkin Tests?To begin, we establish a folder in the project to contain the Gherkin features that we will be writing. In this example, we'll use a BDD practice example to model the behavior of a cashier using Gherkin functions, and we'll do it utilizing these methods.
Suppose we are interested in modeling the behavior of an ATM when we want to withdraw money:
Scenario: As [specific user]Feature: Money withdraw
Scenario: As an existing and enabled user of the ATM, I want to make a withdrawal to get money.
Some key features concerning Feature files:
Features and scenarios
In Gherkin language, the scenarios are examples of individual behavior to establish acceptance criteria, so we may be interested in writing several per functionality to observe different results and make our test more complete (it is recommended to write the positive scenarios first).
Gherkin statements are used to describe the scenarios: Given, When, Then, But and And.
The most important aspect is that the steps define what you want to achieve in the functionality rather than how you want to execute it (this is the responsibility of the step definitions, explained below). This is an example of a poorly constructed scenario:
Scenario: As an existing and enabled user of the ATM,
I want to make a withdrawal to get money.
Given I authenticated with an enabled card
And The available balance in my account is positive
And the teller has enough money
And The cashier has enough paper to print receipts.
When I insert the card in the ATM
And I write on the keyboard the pin of the card
And I press the confirm pin button
And I press the button next to the withdraw money option
And I deposit an amount less than or equal to my available balance
And I press the confirm extraction button
And I press the button to confirm print receipt
.......
Gherkin Feature Files with your tests can be easily imported with TestQuality