Behavior Driven Development (BDD) Testing and Gherkin

Asmitha Raj
2 min readApr 12, 2021

Software testing is a method of ensuring that the software product works as expected and is defect free. TDD (Test Driven Development) is the process of writing test cases from a developers perspective even before the software is fully developed. As the product evolves, the tests may give false results. The recent transitions from waterfall to agile model has resulted in the evolution of BDD from TDD. BDD Is the technique of testing the system’s actual behaviors from the users perspective. This results in a better end product.

* Uses simple human readable syntax which enables every team member to understand the language

* Allows members of all phases (Business Analysts, Developers and Testers etc) to engage in the product development

* Focuses on how the system should behave from the end users perspective

* Reduces coding costs by identifying bugs in the early stage of the development process

* Reuse of code helps in saving time

There are many tools that support BDD. Cucumber is one such tool that reads Gherkin tests. Gherkin is the language used by developers to write tests in cucumber. This language uses simple English making it easy to understand by every team member.

Image by @karenimages from unsplash

Gherkin Syntax

Feature : describes the feature of a software, related scenarios are grouped in a feature

Scenario : behavior of the system

Given : preconditions or initial context

When : event or action to be performed

Then : expected output

And / But : optional — used as conjunction elements

Example

Feature : Login functionality of a social networking site. It can have various scenarios.

Given : The user is already registered

When : The user enters the correct username and password

Then : The user should be redirected to the home page of the social networking site.

Originally published at https://www.numpyninja.com on April 12, 2021.

--

--