What is BDD and how is it different from TDD?

  • What is BDD and how is it different from TDD?

  • TDD is Test Driven Development. This means writing a test that fails because the specified functionality doesn't exist, then writing the simplest code that can make the test pass, then refactoring to remove duplication, etc. You repeat this Red-Green-Refactor loop over and over until you have a complete feature.

    BDD is Behavior Driven Development. This means creating an executable specification that fails because the feature doesn't exist, then writing the simplest code that can make the spec pass. You repeat this until a release candidate is ready to ship.

    In BDD there is a special persons (testers, product owners, others) who writes the scenarios in feature text files:
    Here is a sample using BDD and Gherkin syntax:

    Feature: Account Holder withdraws cash
      Scenario: Account has sufficient funds
       Given the account balance is $100
         And the card is valid
         And the machine contains enough money  
        When the Account Holder requests $20
        Then the ATM should dispense $20
         And the account balance should be $80
         And the card should be returned

    Programmers have special frameworks (for example, cucumber, specflow) that translate such scenarios into tests written using programming language, develop the tests.

    What is the advantage of BDD from TDD?

    • Tests readable for non-programmers.
    • They are easy to change. They are often written in almost pure English.
    • They can now be written by the product owner or other interested parties.
    • The test results are more "human".
    • Tests are independent of the target programming language. Migration to another language is greatly simplified.

    The Difference are:

    • BDD uses specific almost pure English words syntax, but TDD is written with code used in development
    • In BDD, a test is written that can satisfy both the developer and customer, but in TDD you write a test that will only satisfy a developer and the code they write

    BDD has actually evolved from TDD, as a way to eliminate the shortfalls of TDD. So there is absolutely no harm in implementing both approaches – one to support the quality of the code the developer writes, and the other to support the behavior of the system defined by the product owner.

Log in to reply

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2