Software Developers have created many different approaches to tackling software development projects. These approaches/frameworks aim to speed up or simplify the software development process. Some frameworks used in software development include Scrum, Kanban, and Behavior Driven Development (BDD). This article looks at Behavior Driven Development (BDD), meaning we will look at what it is and how it works.
What is Behavior Driven Development (BDD)?
In software circles, Behavior Driven Development (BDD) is an Agile methodology for developing software. During Behavior Driven Development, the developer team writes code that aims to satisfy the various behavioral goals set before development.
BDD aims to unify the project descriptions of technical and business teams by using plain English language that both parties can understand. BDD improves the level of communication and collaboration between developers and non-developer personnel as both groups can easily understand what the project involves.
BDD evolved from Test Driven Development (TDD), with the key difference being BDD has a shared lexicon/vocabulary between all stakeholders.
How Behavior Driven Development (BDD) Works?
In Behavior Driven Development or BDD, you first write BDD behavioral tests before the development team even begins coding. In the beginning, the Behavior Tests should already be running – and failing.
However, as more code is written, the behavior tests begin automatically passing one-by-one as each test’s passing conditions are met by the expanding code.
When all the behavior tests pass, then development is completed.
What are BDD Behavioral Tests?
Behavior Tests describe exactly what a user can expect from a system. A list of expected system behaviors is a kind of ‘contract’ – with all the behaviors a system should have. If a contract passes, it means all the system behaviors are there.
However, if any of the expected behaviors in a system are absent or faulty, then the contract is broken.
Behavior Tests can be done at any stage of the development process – whether it is before, during, or after. However, in BDD, behavior tests must be written/done before development begins.
Anatomy of a BDD Behavior Test
Writing Behavior Tests is a highly collaborative effort that needs input from multiple perspectives and experiences. It should not be left to an individual, instead, business people, developers, and testers should all be involved in the creation process.
A behavior test is written in plain English and it is made up of 3 sections.
The three sections follow a Given-When-Then sequence and they are:
The scenario or context is the initial state or starting conditions of a system. An example context is below:
“Given the bank account balance is $200
The card is valid
The ATM works and has enough money”
An event is an action a user makes on the system.
Expanding further on the above Context example, the corresponding sample event would be:
“When a user (account holder) wants to withdraw $50.”
The outcome is the expected results you get after the starting context has been changed by the user event. In other words, the outcome is the final system state.
Concluding our ATM money withdrawal example:
“Then the ATM should give out $50
The balance should be updated to $150
The user should receive a transaction receipt
The ATM bank card should be returned to user”
Behavior Driven Development (BDD) Benefits
Developers tend to write excess code for various reasons – wasting company time, effort, and resources. BDD guides and reins developers from pursuing unnecessary tangent code. With BDD, developers create exactly what the customer wants – nothing more and nothing less.
Little Learning Curve
BDD is non-technical and uses natural language. Therefore, involved parties do not have to learn a lot of additional knowledge to be on the same page with everyone else.
Pre-Specified Development Goals
Because all the behaviors and outcomes of a project are set before development, it is easy to know exactly when the project is completed. Consequently, cutting down the time spent on overtime. The development team would also not work beyond the project specifications.
Behavior Driven Development (BDD) Drawbacks
Failed Tests Not Specific
Failed tests in BDD do not point out the root cause of the failure; instead, they only notify you that something is wrong or not working. It is up to the developers to find the cause of the fault.
BDD is not Comprehensive
When you use a BDD framework, you still need to incorporate other methods and tools to fully cover all aspects of development. For example, behavior tests are not enough, you still to do unit testing.
BDD vs TDD
Test Driven Development (TDD) focuses on ‘what an application is doing’, whereas in BDD you focus on ‘what a user can see’.
In BDD, the product owner, business personnel, developers, and testers all play a very active role throughout the development process. In contrast, in TDD, the developers are the only group that is active during development.
Another key difference between TDD and BDD is that in BDD you have a specific use case in mind while in TDD you focus on frameworks and libraries. BDD is ideal in low resource environments like smaller businesses whereas TDD is great for larger entities with plenty of resources for exhaustive testing and processes.
5 BDD Tools
Here is a list of some of the tools used in implementing BDD.
- Cucumber (Ruby framework )
- SpecFlow (.NET framework)
- Behave (Python)
- JBehave (Java)
2 Other BDD Test Examples.
BDD Test No. 1
Given the car battery is charged
And there’s petrol in the car
And the engine runs
When I turn the key in the ignition
Then the car should start
BDD Test No.2
Given my bank account balance is $300
And my friend’s bank account balance is $100
When I send $150 from my account to my friend’s account
Then I should have a new account balance of $150
And my friend should have a new account balance of $250
Conclusion – BDD Meaning
The BDD meaning or idea behind it is to describe how an application should behave in very simple language so that both technical and non-technical people can understand and participate in the development process.