by Viktoria Byk | April 12, 2017 8:29 am
Note: this article was updated in August 2019.
Gherkin is a line-oriented language such as Python. The language may serve as project documentation, e.i., describes business logic of the system, and as a basis for writing automated tests using the Cucumber tool.
Gherkin has the structure of the natural language and describes the object in a form of narration. Its main advantage is that the language is comprehensible to humans. Gherkin has 10 keywords: given, when, then, and, but, scenario, feature, background, outline, examples.
Every feature includes several scenarios, while every scenario consists of the list of specified steps. At the beginning of every step, there is one keyword – Given, When, Then, But or And. For example, the input of invalid email by a user should be prevented. Within Gherkin syntax, the same requirement looks like this:
If a user inputs an email that does not include @, when he/she tries to submit the form, the error message with advice to enter valid email should be displayed.
As a result, you have a concrete requirement – acceptance criterion – that is easier to comprehend and that prevents the issue occurrence. Such criteria can be prepared by a Product Manager before the team starts working on a feature. As they are written in a human-understandable way, designers and other members of the project team can easily interpret a user flow.
As it’s been mentioned before, Gherkin is also used as a skeleton for automated tests. It can be implied for Agile projects[2]. Let’s review such cases in more details.
Rather often Agile teams apply BDD (Behavior-Driven Development) approach where software development starts with the preparation of user stories and acceptance criteria. And we’ve already known that these criteria can be written using Gherkin.
For automation of acceptance criteria testing, Cucumber is used. It is a tool that runs automated acceptance tests[3] prepared in BDD format. Cucumber also enables the translation of plain-text descriptions written in Gherkin into automated tests. For example:
To experience Gherkin advantages, you should keep in mind some principles while writing scripts.
Gherkin is a simple language that can be understood by non-programmers. It serves as a format for Cucumber specification and as a functional specification. However, to prepare Gherkin scripts, you should be deeply engaged in business logic.
Source URL: https://blog.qatestlab.com/2017/04/12/gherkin-language-notion/
Copyright ©2024 QATestLab Blog unless otherwise noted.