Behavior Driven Development

Behavior driven development (BDD) is a software development process that evolved from TDD. It makes tests more natural by making English sentences that express certain behavior. It is an outside-in way of developing software, where you make examples of how the software should behave (feedback from stakeholders being either clients, your users or you) to achieve certain goals.

StoryBDD

There are two types of BDD - StoryBDD and SpecBDD. StoryBDD focuses on business and features. Here is a quick and simplified example of a login functionality based on Behat framework. By communicating with stackeholders, developers create login scenario (or an example in BDD):

Feature: Login
  I want to have access to certain page only if I provide
  correct username and secret password

  Scenario: Checking username and password
    Given I am on a login page "login"
    And I provide username "foo"
    And I provide password "bar"
    When I run "Login"
    Then I should see:
      """
      Login is successful.
      """

This ensures that developers understand how stackeholder want this functionality to work, and that stackeholders expect this functionality to be implemented like developers are planning to implement it.

Instead of writing unit tests like with TDD, the scenario is also your test before writing the code.

SpecBDD

The second type of BDD is SpecBDD which focuses on technical behavior of code. Specifications describe how the certain code should behave. Instead of testing part of your code, you are describing that part of the code.

See Also

Articles and tools you should check out:

GitHub OctocatFound a typo? Something wrong with this content? Just fork and edit it.

Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all the contributors.