BDD: Your guide to Behavior Driven Development and BDD frameworks

Find all you need to know about Behavior Driven Development (BDD) and the various BDD framework tools available out there.


TABLE OF CONTENTS

  1. What is BDD/ Behavior Driven Development?
  2. Past instances of the use of BDD
  3. Applying BDD practices to software development and testing
  4. How to choose BDD frameworks?

What is BDD/ Behavior Driven Development?

Behavior Driven Development is a process used in agile software development which makes use of business focused language to determine how an application should work. It is a branch of the principles that fall under TDD or Test Driven Development. A BDD framework is used to make software testing easily understandable for all in the team.

Closely related to TDD and ATDD, BDD aims to simplify the collaboration between the development, testing and business teams. In BDD, too, tests are written before writing the code. However, when making use of BDD frameworks, the tests are written in plain language so that anyone can understand it. Furthermore, these tests are explained in terms of how the app should ‘behave’ when the user is making use of them. Examples are made use of to ensure complete clarity. Essentially, BDD shifts the focus from test based to behavior based.

During the continuous testing cycle, BDD can be used for the automatic acceptance of cases. The expectations that the client has of the developer and testing team will be minimized by setting the cases at the start in an easy to understand format.

Now that you know what BDD is and a bit about BDD frameworks, it’s time to learn more. In the below sections, we’ve explained how BDD came into being, what the various BDD framework tools are, and the basics on how to implement BDD.


behavior driven development and bdd framework

Past instances of the use of the BDD framework

Chris Stevenson wrote TestDox (aka agiledox) in 2003. This tool automatically generates simple documentation from JUnit tests. It is considered as the ancestor of BDD. Later, in 2004, the GWT or Given-When-Then framework was proposed by Chris Matts and Dan North. This expanded the scope of BDD to business analysis and documentation.

In the same year, North released JBehave, a framework for Behavior Driven Development. He did this to test his hypothesis about placing more importance on behavior than the tests themselves. A couple years later, in 2006, Dan North documented this approach of his in ‘Introducing BDD’.

Over time, the app development community got more invested in BDD. This saw an increase in the release of BDD framework tools such as RSpec and Cucumber in the more recent years.

Applying BDD frameworks to software development and testing

Behavior Driven Development can be split into a few stages as described below. These are meant to eliminate any extra work by ensuring that the problems are dealt with early on.

  1. Discovery: Here, the various teams have a discussion about the various tests that need to be developed. The product owners, business stakeholders, end users, developers, testers and other teams all get together to define the business requirements as tests. The desired outcomes are defined.

  2. Development: Based on these desired outcomes, the developers work on building apps that behave in a certain way. This ensures that there is no failure.

  3. Revisiting: As the term suggests, in this step the various stakeholders revisit the app developed to ensure that the behavior is smooth. This also helps to ensure that only required features are built and there’s nothing unnecessary.

How to choose BDD frameworks?

To choose BDD frameworks accurately, it’s important to understand what exactly a BDD framework does. In the first step when using BDD, the stakeholders meet and discuss the various requirements. These are stated in plain language, usually Gherkin or other languages specified by the domain (DSLs). BDD test automation frameworks then read these executable specifications and perform tests to ensure that the software meets the needs.

Every major programming language has a BDD framework. The fundamental goal of all is the same and they are mostly derived from Cucumber and JBehave. Choosing BDD tools would depend on your particular needs. The following are some of the most popular BDD frameworks out there with an explanation of their offerings so you can choose with ease.


Cucumber

Cucumber is a very popular BDD testing framework. It was originally written in Ruby and now supports a variety of languages such as JavaScript and Java. Cucumber allows defining the application’s behavior using plain English language text. The grammar of this text is defined by a language called Gherkin.

Cucumber is a non-technical language and makes use of the GWT (given-when-then) framework to structure the software’s behavior. It promotes the BDD practice and puts emphasis on clear requirements from the start.


SpecFlow

SpecFlow is a famous BDD framework for Microsoft, .NET languages. SpecFlow needs a separate unit test runner to run the scenarios when making use of the free, open source version.

SpecFlow+, the premium version of the tool, has a BDD-friendly runner. It also comes with Microsoft Excel Integrations, premium support and living documentation. SpecFlow brings the same features to the .NET arena that Cucumber does to Ruby. The cases can be specified in a plain-English language in a readable format using Gherkin.


JBehave

Meant for Java and related languages, JBehave is also a very popular BDD framework. It works smoothly with Scala, Kotlin and other JVM languages, too. It’s well known among both testers and developers. The tool comes with some features like parameter injections for parameterizing tests and composite steps.

However, JBehave does not offer all the same features as Gherkin does. Due to this, for Java and JVM based apps, Cucumber-JVM is also considered alongside JBehave.


Codeception

When using PHP, Codeception is a popular choice for BDD testing frameworks. Along with BDD, Codeception also does full stack testing. This includes unit testing, API testing, and functional testing. The tool offers a more flexible dev-focused approach to testing.


How to pick a BDD framework based on the programming language you use

If you are looking for tools apart from the ones mentioned above, here are some suggestions based on your programming language:

  1. Microsoft .NET, C# -
    SpecFlow, NSpec, LightBDD

  2. JVM, Java, Scala, Kotlin, Closure -
    JBehave, Cucumber-JVM, JGiven, Concordion, Spock

  3. PHP -
    Codeception, Behat

  4. JavaScript -
    Cucumber.js, Yadda, Vows

  5. Ruby -
    Cucumber, Spinach

  6. Python -
    Lettuce, Behave, Radish