What is Behavior Driven Development?

April 9, 2024
5 min read
Share this post

In the article Cucumber tutorial for beginners, we used the term Behaviour Driven Development. In this blog post, we will read about this term on, what is Behavior Driven Development(BDD), and how to write test cases in BDD.

What is Behavior Driven Development?

Behavior Driven Development is a software development process originated from Tests Driven Development (TDD).
But why do we need BDD? Gone are the days when interactions were minimum, Once the customer accepts the requirements, accepted requirements go for the development phase and then code goes to the testing phase. Now in the testing phase, test cases are generated based on the code that they get from the development team. If you see, Code takes time to understand and moreover, it is a skill dependent task, as understanding code to write test cases requires the testing team to first fully understand the code which might get delayed due to a limited skill set of testers.
Here, BDD comes for the rescue. The motto behind introducing BDD was to illustrate the behavior of the system in a readable and understandable language that is understood by everyone involved in the development.

Key features of BDD:

  1. One can notice that there is a clear shift in the thinking from “Tests” to “Behavior”.
  2. BDD focuses on what the system should do not on How it should be implemented in the system.
  3. Language is ubiquitous, thus easy to describe and understand for the stakeholders.
  4. Provides shared processes and shared tools, thus promoting communication to the software developers, business analysts, and stakeholders to collaborate on software development to deliver quality software with business values.
  5. We can say that BDD is driven by Business Value.
  6. Cucumber or JBehave acts as an enabler, thus acting as a bridge between Business and Technical language.

BDD Practices:
There are 2 main practices of BDD:

  1. Specification by Example (SbE)
  2. Test-Driven Development (TDD)

Specification by Example uses Example to illustrate business rules, on the other hand, Test-Driven Development converts these examples to human-readable and executable specifications.
There are 2 terms Cucumber and specFlow that are used most frequently if you ever read about BDD. What do they mean?
Cucumber is a testing framework that supports BDD.
Cucumber helps to write business rules in an easily understandable language Gherkins. Cucumber gems will later execute these stories.
specFlow is inspired by the Cucumber framework that is written in Ruby. specFlow is more or less the same concept where it tries to bring the concept to the .NET world. It allows you to write features in a human-readable Gherkin format.

Why do we go for BDD Framework?

In a Software Development Lifecycle what exactly happens is, Client is responsible for communicating the requirements to the requirements gathering team. But, the challenge here is that the person who is developing the software is not the same as the person who has this idea. Now the need of the hour is to communicate the idea to all the members of the project so that everyone, even the tester should be aware of what the client actually wants.

Most software projects involve a team of several people working together. So, in such a situation, communication plays a vital role.

Good communication does not only mean to communicate your ideas to other members, but it also means to solicit feedback to ensure that you have been understood correctly.

This was the reason for the Agile methodology for following an incremental approach, where software product is delivered in small increments, where features are incremental in nature.

Tests written in Cucumber interacts directly with the development code, but they are written in a language that is easily understandable by the business stakeholders.

Example of BDD Test:

Let’s consider a Login Scenario, were entering the correct username and password means successful login and incorrect login, on the other hand, will show an option to recover the password. So, what are we waiting for? Let’s get started.

Feature: Login
Login should be easy and user-friendly.
Scenario: Successful login
Users will be able to see My Account Page.
Given I have chosen to log in
When I login with valid username and password.
Then I should see My Account Page.
And I should be able view to my name on My Account’s Page

Scenario: Invalid Password
When someone tries with an invalid combination of username and password.
Given I have chosen to Login
But I entered the registered email address and a password
Then I should be told that invalid username or password.
And I should be offered the option to recover the password.

From the above code, you could see that anybody can easily understand the tests that are conducted and on the other hand, can easily give powerful impact by enabling people to understand what system will do before the system is built. Anyone can read and understand the tests and will be able to give you feedback.
I hope this article will help you to get an idea about how to use Gherkin and Why BDD is really important.

Rupesh Garg
Rupesh Garg
CEO and Chief Architect
Our blog

Latest blog posts

Discover the latest in software testing: expert analysis, innovative strategies, and industry forecasts
Software Testing

Top 12 Software testing myths debunked

Rupesh Garg
Rupesh Garg
May 7, 2024
5 min read
Software Testing
Testing Tools

Exploring Software Testing with Selenium Framework

Rupesh Garg
Rupesh Garg
May 6, 2024
5 min read
Software Testing
Testing Tools

Exploring Software Testing with the Right CI/CD Toolset in 2024

Rupesh Garg
Rupesh Garg
May 6, 2024
5 min read