Behaviour Driven Development (BDD) is an agile software development strategy that aids to establish communications between the stakeholders of the software product. It helps mitigating the small gaps of communication between understanding the product functionality and its performance in the real time. This practice was introduced in by “Dan North” in the year 2003 and has become a very popular trait in the recent era of software development. This includes acceptance test criteria and custom test driven development practices as a part of the extreme programming.
BDD focuses on projecting a clear understanding of the software behaviour through discussion with the stakeholders. It extends the features of the “Test Driven Development” in a natural language procedure that helps the non-programmers contribute to the better of the software product. That is the reason why this practice gives a clarity on why the code has to be written, rather than the technical details of the code. It also minimizes the radius between technical aspects of the code and the domain specific language that a business stakeholder uses in his day to day life. It helps in iterating each element of code that provides some aspect of the behaviour which in collaboration with the other modules of the software provides the entire application behaviour. Thus it functions very similar to any automation test based code, but helps it making easier and give a very high level brief about the technical functions of the software without diving in much deep.
The practices of BDD include:
- Establishing the goals of the different stake holders who are directly related to the business.
- Establishing features which will achieve those goals using feature injections.
- Establish behaviour of the application or of units of code using examples.
- Automating the selected examples to provide quick feedback and regression testing.
The Gherkin Language
The Gherkin language is one of the important aspects of the Behavioral Driven Development strategy. It is a business readable domain specific language that let’s the members of the team understand the behaviour of the software without understanding the details of how the backend code has been implemented.
Gherkin serves two purposes – documentation and automated tests. Gherkin’s grammar is defined by Treetop grammar which is a part of the “Cucumber” codebase. There are a few conventions while using the gherkin language, 1. Single Gherkin source file contains a description of a single feature and 2. The source files has a
.feature extension. Like Python and YAML, Gherkin is a line based oriented language that uses indentation to define the language structure. Line endings terminate statements (eg, steps). Either spaces or tabs may be used for indentation (but spaces are more portable). Most lines start with a keyword.
Feature: Validate the features of the Dashboard Scenario: Hit the URL and validate title of the page When I visit url "http://www.test123.com/" Then the title should match "Automatad - Ad Solutions, Automated." Scenario: Click on login and switch tab When I click on the element with xpath "//span[text()='LOGIN']" Then I switch to the new tab Then the title should match "Automatad - Login" Scenario: Enter username, password and validate "admin dashboard" When I enter element with name "email" as "firstname.lastname@example.org" When I enter element with name "password" as "password123" When I click on the element with xpath "//button[@type='submit']" Then I check the page load status Then I should see the element having "CLASS" as "sidebar-header" Then I wait for "20" seconds Scenario: Validate the filter for dashboard When I click on the element with css "body>button:nth-child(5)" Then I wait for "2" seconds Then I enter filter data for dashboard When I click on the element with css "#chat > div > div.view.bg-white.pull-right.clearfix.m-t-20 > div > button.btn.btn-lg.btn-primary" Then I wait for "2" seconds
Tools of the trade
Few of the BDD based platform that can be utilized to carry out BDD implementation are as follows:
PHP based BDD framework that can be used for creating unit and regression based test automation frameworks.
Python based BDD framework that can be used for creating unit and regression based test automation frameworks.
Java based BDD framework that can be used for creating unit and regression based test automation frameworks.