BDD vs TDD

BDD vs TDD
BDD vs TDD

Many of you have asked about the difference between TDD and BDD (BDD vs TDD). I’ll try to answer that question while simplifying the concepts as much as possible.

TDD (Test-Driven Development)

TDD, or Test-Driven Development, is a software development technique where you write unit tests for a function (at the code level) before writing the actual code for that function. While this approach significantly reduces the chances of future regression issues, its primary purpose is to guide developers in writing better application code. Knowing the expected end results helps developers start in the right direction from the beginning.

Although this concept might be bewildering for developers new to it, it has become a standard development practice, leading to undeniable excellence in quality.

The TDD Cycle

TDD follows a work cycle to ensure optimal quality of unit tests:

  1. Write the unit test.
  2. Run the test and check if it fails (indicating that the class is not yet coded).
  3. Write the minimum code required to make the test pass.
  4. Re-run the test and check if it now works.
  5. Complete the code for the entire class.
  6. Verify that the test still passes (no regression).

If you want to learn more about this concept, I strongly recommend reading our dedicated article on the subject.

BDD (Behavior-Driven Development)

BDD, or Behavior-Driven Development, is an Agile practice created by Dan North in 2003. Its goal is to create functional tests using a natural language that everyone can understand.

From a technical perspective, BDD fills the gap where testing each piece of code does not guarantee validating complete behaviors. Just because the functions work individually doesn’t ensure the expected overall behavior.

However, the fundamental philosophy of BDD is to guide development based on expected behaviors. More importantly, this BDD framework encourages bridging the gap between technical and functional teams, similar to the collaboration desired by Agile methodologies. There’s nothing better than harnessing collective intelligence to bring a product to maturity. Developers are guided by the behaviors expected by users.

Tests are written using a natural language called Gherkin. Here’s a simple example where the bold parts represent the mandatory basic structure for writing these tests:

Given I am the customer on the product page
When I click “Add to Cart” on the product with ID “255”
    And the stock is “3”
Then the product is added to the cart.

This sentence will be automatically transformed by online code applications, and developers will only need to fill in the behaviors within the code functions to write the test.

Once the test is properly written, developers will write the resulting functions.

If you want to learn more about its application, don’t hesitate to check out our article on the subject.

BDD vs TDD

TDD guides development function by function. For those not closely associated with the development field, it’s important to understand that a function in development represents a small unitary behavior, not a scenario. Even the simplest scenarios are sequences of functions.

BDD allows testing all the expected behaviors for a user story to be developed. Typically, the goal is to cover all possible test cases with BDD.

Here’s a simplified diagram for visualization:

TDD vs BDD
TDD vs BDD

Conclusion: BDD vs TDD

I hope this article has answered your question. If you have any more questions about BDD vs TDD, please feel free to leave a comment.

(Visited 75 times, 1 visits today)
About Judicaël Paquet 368 Articles
Judicaël Paquet (agile coach and senior devops) My Engagements in France and Switzerland: - Crafting Agile Transformation Strategies - Tailored Agile Training Programs - Raising Awareness and Coaching for Managers - Assessing Agile Maturity and Situational Analysis - Agile Coaching for Teams, Organizations, Product Owners, Scrum Masters, and Agile Coaches Areas of Expertise: Scrum, Kanban, Management 3.0, Scalability, Lean Startup, Agile Methodology.

Be the first to comment

Leave a Reply

Your email address will not be published.


*