Introduction
Behavior-Driven Development (BDD) is a software development methodology that emphasizes collaboration between developers, testers, and business stakeholders in the software development process. It is an extension of Test-Driven Development (TDD) and combines the principles of Domain Driven Design (DDD) with the best practices of Agile software development.
BDD encourages the use of a common language, called "ubiquitous language", that can be understood by all stakeholders. It promotes the creation of user stories and acceptance criteria to capture the desired behavior of the system, which are then translated into executable specifications. These specifications guide the development process and serve as an acceptance test suite for the software. This helps in identifying key scenarios for each story and also eradicate ambiguities from requirements.
In BDD, Examples are called Scenarios. Scenarios are structured around the Context-Action-Outcome pattern and are written in a special format called Gherkin.
The scenarios are a way of explaining (in plain english) how a given feature should behave in different situations or with different input parameters.
Because Gherkin is structural, it serves both as a specification and input into automated tests, hence the name “Executable Specifications”.
Feature files are text files with .feature extension, which can be opened by any text editor as well as readable by any BDD-aware tool, such as Cucumber, JBehave or Behat.
Feature files should start with the context of the feature (which is essentially the story), followed by at least one scenario in the following format
Feature: Some terse yet descriptive text of what is desired
In order to realize a named business value
As an explicit system actor
I want to gain some beneficial outcome which furthers the goal
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
And yet another action
Then some testable outcome is achieved
And something else we can check happens too
Scenarios in feature files should focus on the “what” rather than the “how”. The scenarios should be concise and to the point, so that the reader can quickly grasp the intent of the test without having to read a lot of irrelevant steps.
The BDD Process
Benefits
Best Practices
BDD Adoption
Practice | MVP | MVP+ |
---|---|---|
Establish discovery and formulation practices |
+ |
+ |
Keep requirements and test cases in .feature files |
+ |
+ |
Enable automated acceptance testing as part of the CI process |
|
+ |
Develop automated acceptance test before development |
|
+
|
Roles
Name | Responsibilities |
---|---|
|
Participate in joint requirements review session (3Amigos) to create user stories and acceptance steps together. |
Product Owner |
Accept development user stories created in a collaboration of all interested parties (Business, Development, Testing) |
Test Automation Engineer (TAE) |
Automate user stories acceptance tests created in a collaboration of all interested parties (Business, Development, Testing) |
Developer |
Implement or adjust specific product behavior to pass user story acceptance tests created in a collaboration of all interested parties (Business, Development, Testing) |
QA Specialist (Functional SME) |
Perform any additional manual exploratory testing on top of the automated acceptance testing |