Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Behaviour Driven Development (BDD)

DZone's Guide to

Behaviour Driven Development (BDD)

This brief introduction to this software development strategy will help you understand its advantages, the language it uses, and its most popular test frameworks.

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

Behaviour Driven Development (BDD) is an agile software development strategy that aids to establish communication between the stakeholders of a software product. It helps to mitigate the small gaps of communication between understanding the product functionality and its performance in 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 extreme programming.

BDD focuses on projecting a clear understanding of the software's behavior through discussion with the stakeholders. It extends the features of test-driven development in a natural language procedure that helps the non-programmers contribute to the betterment of the software product. That is the reason why this practice gives 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 behavior, which in collaboration with the other modules of the software, provides the entire application's behavior. Thus it functions very similarly to any automation test-based code, but helps make it easier and give a very high-level brief about the technical functions of the software without diving in too deep.

BDD Practices

The practices of BDD include

  • Establishing the goals of the different stakeholders who are directly related to the business.
  • Establishing features which will achieve those goals using feature injections.
  • Establishing behavior 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 lets the members of the team understand the behavior 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. A single Gherkin source file contains a description of a single feature and 2. The source files have 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 (e.g. steps). Either spaces or tabs may be used for indentation (but spaces are more portable). Most lines start with a keyword.

Feature: Validate the feature for proper input of credit card number

Scenario: Validate credit card number
 When I enter a card number that is less than 16 digits long
 And all the other details are correct
 And I submit the form
 Then the form should be redisplayed
 And I should see a message advising me of the correct number of digits

Tools of the Trade

A few of the BDD-based platforms that can be utilized to carry out BDD implementation by creating unit and regression based test automation frameworks are as follows:

Behat: A PHP based BDD framework.

Behave: A Python based BDD framework.

JBehave: A Java based BDD framework.

The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

Topics:
bdd ,devops ,software development ,test automation

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}