top of page

Behavior Driven Development(BDD) With Gherkin

In software engineering, behavior-driven development (BDD) is an Agile software development process that encourages collaboration among developers, QA and non-technical or business participants in a software project. BDD is a software development process that is driven by the behavior of an application and is sometimes called as an extension of the Test Driven Development (TDD) approach. Since it has emerged from Test Driven Development it’s worthwhile to have an idea about TDD in order to understand BDD properly.

Test Driven Development(TDD)

TDD, as the name implies, is driven by tests. Here, first the software requirements are being converted to test cases before the software is fully developed. Once the development is completed the test case corresponding to the implemented functionality should pass. Then the code can be refactored to improve its quality. This is opposed to traditional way of software being developed first and test cases created later.

TDD approach helps make an application stable. However, it is difficult to understand the automated tests for non-technical team members and other stakeholders. In order to address this issue, BDD came into the picture.

In BDD, first the test cases are first defined on the frontend in a human-friendly language, mostly ‘Gherkin’. Once the feature is developed, the test cases are automated in some programming language. The implementation is kept in the backend, mapping each step to the frontend.The test cases are defined to replicate the behavior of the system thus the name ‘Behavior Driven Development’.

Behavior Driven Development Tools

There are several open-source and paid tools available for BDD framework. Here are some of the common examples below.

1) Cucumber Studio

2) Behave

3) JBehave

4) SpecFlow

5) Jdave

6) Instinct

7) Specs

BDD Tool Selection

In order to implement BDD framework any one of the tools mentioned above can be selected based on the below factors:

1. The programming language being used in the source code of the product/project.

2. Nature of the Project.

3. Team competency, team discussions and other software requirements.

4. Approved budget in case of choosing a licensed tool.

However, among all of the above BDD tools, Cucumber is the most common and widely used tool. Cucumber was written in Ruby programming language and used for Ruby testing initially. However, cucumber is now supported by other programming languages also like JAVA, .Net.For writing specifications or business behavior in the frontend for BDD Frameworks, Gherkin is the most widely used language.


Gherkin is a business readable language which helps you describe business behavior without going into details of implementation. It is a domain specific language for defining tests in Cucumber format for specifications.

Writing Gherkin Test

There are some keywords used in Gherkin to define complete tests including pre-condition, test description, expected outcome etc. Here are some of the common keywords used in gherkin language:

1. Feature

Each Gherkin file starts with a keyword Feature, followed by a definition of the logical test functionality to be tested on that feature file. In other words, the feature is a description of what the application is supposed to do. Feature keyword is also used to group multiple scenarios together. Feature keyword is found at the start of a feature file.

2. Descriptions

When required, free-form descriptions could be written underneath the given keywords, as long as all the lines are being written without any keyword.

3. Scenario

Each feature file may have multiple scenarios, and each scenario starts with Scenario: followed by scenario name.

4. Given, When, Then, And, (Steps)

Given step is used to describe the prerequisites before a test case execution can start.

When cucumber runs a Given step, it configures the system to be in an already defined state, such as object configuration or adding required data to a test database.

When step is used to describe an event and an action. This can be a person or user interacting with the software/system. Also, it could be an event triggered by another or an external system.

It basically comprises of the action performed on the system.

Then step is used to describe an expected result or an outcome.

And step is used when there are multiple steps for the one type of step like for eg. 2 conditions that should be valid as a prerequisite then after ‘Given’ the two steps can be separated by an ‘And’.

An Overall Feature File Example

Below is a sample of how an overall Feature file looks like:

Feature: Different Users logging in a datastructure portal app

Scenario 1: Admin user login

Given: The User opens the datastructure portal app giving the URL in the web browser

And: The user clicks on the sign in link

When: The user enters the username and password credentials in the textboxes

Then: The app must login the admin user and show the admin user name suffixed with the word “admin” in the top right corner of the webpage

Scenario 2: Business user login

Given: The User opens the datastructure portal app giving the URL in the web browser

And: The user clicks on the sign in link

When: The user enters the username and password credentials in the textboxes

Then: The app must login the business user and show the business user name in the top right corner of the webpage

Advantages Of BDD Framework

Enlisted below are the various advantages of BDD.

1) Coverage of User Stories

Every resource in the software development phase can contribute to the BDD framework. The easy concept of layman text in the form of feature file allows the stakeholders of technical resources to write the scenarios in Gherkin language using the user stories. The compatibility of the plain text helps to gain maximum coverage on testing.

2) Clarity of Scenarios

Gherkin language uses plain English text that is focused on the outcome of the product which is being tested/developed using BDD.

As feature file separates the technical description in a different step definitions file for automation testers, it smartly helps a non-technical person to understand the automated test easily. Readability power of gherkin guarantees the clarity of scenarios to each of its user which in turn, helps in building the right product.

3) Automation of Test Scenarios

Cucumber implementation in a BDD framework allows an automation tester to easily initiate the scripting with the right approach. Easy language of cucumber scenarios helps them understand the functionality in a better way.

Cucumber is a language-independent plugin as it is compatible with many programming languages.

4) Parameterization in Feature File

A user can parameterize the gherkin steps in the feature file to obtain reusability in the file.

For Example, if a user is working on a bank application where he logs in to the application again and again. Such kind of steps could be parameterized with a different set of data and it saves time for the tester.

While writing the scenarios, the user has to define the feature file steps in such a way, so that the user can use the common functionality easily.

5) Continuous Integration – Easy to Integrate

Cucumber also supports working with Jenkins. You can run the cucumber test execution in Jenkins and also implement the same in Jenkins slave machines. The cucumber reporting plugin also provides users with an expanded view to track test scenarios.


Thus, BDD helps bridging the gap between developers and business and has been quite successful in making the implementation as close to the behavior as possible.

196 views0 comments

Recent Posts

See All


Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page