I recently read quite a few blogs regarding test-driven development (TDD), with many of them referencing behavior-driven development (BDD). This left me curious to learn about BDD and how it was different from TDD. Phillip Rogers does a great job breaking down what BDD is, the three principles of BDD, and some examples of BDD with Gherkin in his blog: “Behavior-driven development principles and practices.” (https://blog.logrocket.com/product-management/behavior-driven-development-principles-practices/#:~:text=Behavior%2Ddriven%20development%20(BDD),%2C%20domain%2Dspecific%20scripting%20language.)
What is Behavior-Driven Development?
Behavior-driven development (BDD) is a product management approach focusing on defining system behavior from the user’s perspective. It emphasizes user interaction, collaboration among stakeholders, and aligning the product with user needs. BDD is a test-first development method.
3 Principles of Behavior-Driven Development:
- What the software could do: Discovering and understanding customers needs to avoid building the wrong features. Techniques like impact mapping help prioritize features based on customer value.
- What the software should do: Collaboratively writing structured documentation (executable specifications) articulating user needs. This involves using scenarios and examples in a given-when-then format to describe user behaviors.
- What the software does: Automating desired behavior based on specifications, writing code, and iteratively improving both code and tests. This aligns with the test-driven development (TDD) process of writing failing tests, writing code to pass tests, and refactoring.
Behavior-Driven Development practices:
Impact mapping: A visual technique that reinforces what user outcomes are most important and are therefore more important to the project.
Story mapping: A visual technique that is used to maintain an understanding of what specifications are needed for a feature.
Three amigos: Forming sub-groups with different skill sets to work together. This brings different perspectives and thought processes into groups that may not have been there otherwise.
Benefits of Behavior-Driven Development
BDD being focused on the users’ perspective gives an improved understanding of the users’ goals. The tests created for BDD are typically higher level tests covering user scenarios. This ensures a high test coverage. Other benefits include enhanced collaboration, code reuse, and reduced rework as required changes are more likely to be seen early on.
Behavior-Driven Development vs Test-Driven Development
BDD and TDD are both test-first development methods that require planning and understanding of the project before beginning development. So, how are they different? TTD is mainly focused on the functionality of a feature. Whereas, BDD is focused on the users’ experience with that feature. BDD is more focused on testing specific scenarios a user may encounter. One notable difference is the fact that a single developer can do TDD where-as the amount of insight needed to do BDD requires everyone from developers to stakeholders,