Article

3 minutes on... Behaviour-driven development

What is behaviour-driven development and how does it produce better software?

Behaviour-driven development (BDD) is an approach to building software widely used by agile and DevOps teams to create high quality software, faster.

Its origins lie in a similar methodology called test-driven development, where a test for a particular unit of software is written before the software is actually built. This ensures that the development process is driven by objectives, and the end product fulfils its function.

Some problems with this approach are that a focus on testing doesn't help to inform other aspects of the software development process, such as which features are the most important from a business perspective and should therefore be prioritised. The amount of testing going on (test coverage) can sometimes be pursued as an end in itself, rather than as a means to high quality software. Finally, a knowledge gap can also arise between developers and business teams unfamiliar with the language of software testing and development.

Behaviour-driven development was created by Daniel Terhorst-North as a way of addressing these issues, as well as improving communication and collaboration between business and technical teams to release greater value from software.

BDD provides a methodology for software development and a language to discuss it that both technical and business teams can understand.

Instead of talking about 'tests' it instead focuses on 'behaviours' of a piece of software, describing what it does in certain scenarios. These scenarios should be based around user stories to link software features to business needs. They follow a user story framework: As a [persona]… I [want to] … [So that] … and a 'given, when, then' framework which applies user stories to specific settings.

In BDD, tests are still extremely important, but they are given titles in plain sentences so that everyone can clearly understand their function and see how the software behaves. This provides an opportunity to discuss business value, by asking the question: 'What's the next most important thing the system doesn't do?' BDD therefore helps to identify and prioritise successive features for development.

The language of behaviour-driven development

  • a focus on behaviours not tests.
  • based around user stories, As a [persona]… I [want to] … [So that] …
    • for example: As a customer, I want to shop online, So that I don't have to travel to the shop.
  • scenarios describe how the software should behave in certain settings via the 'given, when, then' framework.
    • in an ecommerce example, this might be: Given the item is in stock, when the customer clicks 'add to basket', then the item is added to their basket.
  • test names must begin with 'should' – this keeps the behaviour of the software focused. In a data input field for customer names, for example, the code might read: testShouldFailForMissingSurname

Author

Sarah final 3
Sarah Finch
Research and Insights Manager
Foundry4

Sarah is renowned for her ability to communicate complex concepts with clarity. She plays a central role in managing the insights programme at Foundry4.

View profile