Articles

Behavior-driven development (BDD): capturing software behaviour in plain English

Daniel Martin

10 min

As the term signifies, behavior of the developed software brings about the behavior-driven development (BDD) approach. This methodology is based on customers' expectations and perspectives. Daniel North, a pioneer of this concept, published an article on BDD in 2006 that soon gained popularity, and since then, the BDD approach has been widely adopted by a lot of software development companies.

BDD describes the set of behaviors that the user can expect from the software, and this methodology is generally applied by product managers and business analysts. Since it is written in plain English, even those without any technical knowledge can understand the expected software behavior. It bridges the gap between a business team and a technical team.

This article explains the basics of behavior-driven development, and provides you with the examples, scenarios, and the list of popular BDD tools.

When to use behavior-driven development

BDD tools are not testing tools – they help you get a common understanding of how the software should behave. It’s mainly applied in the use case scenarios where a business team has a strong reason to assess the system behavior. It can be synced with integration tests, end-to-end tests, etc. You can integrate the BDD approach into the various scenarios, including the one when you build a web app or a mobile app using a low-code development platform.

BDD scenario example

Here is a simple behavioral scenario for an ATM written in plain English, using Gherkin syntax, and having the Given-When-Then structure:

Given the account balance is 100 Dollars

            And the ATM contains the cash

When the Account holder requests 20 Dollars

Then the ATM should dispense 20 Dollars

            And the account balance should reflect 80 Dollars

In the Cucumber tool, you write these tests in Gherkin so that even non-tech-savvy individuals could understand them. When your developers get the tests, they can import the test scenarios into their development tool, and then automate the scenario steps accordingly. Once you stabilize the flow, they can regularly include these scenarios into the automated tests.

BDD scenario structure

The scenario includes 3 sections – Context, Events, Outcome.

  • The Context section reflects the list of things that should be true or ready before you get started.
  • The Events section displays what a user does. If there are multiple events, they should be placed in the correct sequence. Note that this section shouldn’t list any details displayed in the UI, or the implementation details not counted as a behavior.
  • The Outcomes section includes the expected result you get after the specific user’s actions assuming that the needed events have happened.

If a behavior functions appropriately according to the BDD scenario, the feature is marked as working. Every feature is associated with a feature file, and the set of behaviors is termed as a contract.

How BDD aligns with an agile mindset

Behavior-driven development encourages the collaboration between business analysts, developers, and QA engineers. Due to the constant cooperation, they share the overall understanding of the business requirements taking into account the customer’s perspective as well.

We can also define behavior-driven development as a set of practices that helps you enable your teams to deliver software iteratively and incrementally. This set of practices includes Discovery, Formulation, Automation. They can be integrated with any of the agile methodologies like Scrum, Safe, etc.

How BDD improves test automation

Several development and automation test tools can be integrated with behavior-driven development tools. As a rule, developers and testers formulate BDD scenarios based on a discovery phase and the results of the collaboration with business analysts, an Ops team, etc.

Test automation developers conduct test automation before the implementation of the code in production. Generally, the steps are the following:

  1. Create a scenario.
  2. Add features to the scenario.
  3. Create (or import) the feature files/descriptions associated with the particular features in the integrated behavior-driven development tools.
  4. Generate step definitions, and create the script code using dev tools.

For example, you have a feature with the context: “Given the car has started”. Then, when generating the step definition, you’d see the associated code as per the programming language in the development tool:

Given ("The car has started", function ())

{

// Code here

}

The function is run when the scenario is triggered.

  1. Run the behavior-driven development scenarios.

When a QA engineer generates the step definitions, he's associating them with the script code for these scenarios written in Java, VBScript, Javascript, Python, C++ Script, C# Script.

Top 3 BDD tools

Most popular BDD tools can be easily integrated with the development tools any dev team uses. Eclipse IDE, TestProject, etc., allow integration with the following BDD tools.

  • Cucumber. This tool has a free Open Source version – Cucumber Open, and the paid version with a free trial period – Cucumber Pro. This version offers you CucumberStudio and Cucumber for Jira. With Cucumber Open, executable specs are validated against your code. CucumberStudio, in its turn, simplifies the collaboration between your teams. They even offer the Cucumber School, which provides tutorials to help learn more about the tool. It supports several programming languages including .NET, Python, Java. According to the research, the Cucumber tool is much more widely used than other BDD tools.
  • SpecFLow. Free SpecFlow Open Source utilizes .NET and C# methods. Visual Studio allows you to build feature files & automation code. You can use the Gherkin editor at the formulation phase when writing feature files, downloading them, and sharing – even without setting up the Visual Studio. SpecFlow+ Runner is used at the automation phase as a test runner boosting the automation productivity. SpecFlow+ LivingDoc helps you generate living docs and reports, and further share them with your team members without the need to use Visual Studio for that. SpecMap serves as a story map extension for Azure DevOps, and allows for integrating with Azure Boards.
  • JBehave. This is an Open Source behavior-driven development framework created by Daniel North who conceptualized BDD. JBehave can be integrated with Selenium, Eclipse, and even more tools.

Collaboration – a secret ingredient to make BDD successful

It can be tough to implement behavior-driven development without enough collaboration between business analysts, developers, QA engineers, an Ops team, etc. This way of working aligns perfectly with a DevOps, or a DevSecOps approach. Thus, all the team members are encouraged to be constantly in sync. When opting for a siloed working approach, you’ll hardly succeed in BDD.

If you choose to adhere to the behavior-driven development methodology, make sure that your team starts collaborating from the discovery phase. The three amigos – BA, Dev, and QA teams – interact with each other while gathering the requirements and defining the specifications. Constant communication and quick feedback are vital in the BDD process.

Wrap-up

When following the behavior-driven development methodology, you combine both business and technical aspects. BDD is not a simple testing activity – it’s a technique for designing & developing your software. It has also proven to enhance test automation in many ways.

January 21, 2021

Latest articles

Don't want to miss anything?

Get updates on the newest stories, case studies and tips right in your mailbox.