BDD TDD in a BDD Way - Behavior Driven Development

What is BDD TDD in a BDD Way?

Some people believe that the term “Acceptance Tests” is misleading in TDD. Acceptance tests mean the expected behavior of the system. If we observe the Agile practices the collaboration of the development and testing team and interactions with the customer and other stakeholders is considered. It has marked the urgency of usage of terms which are to be understood by all the people involved in the project.

TDD more involves about the term Behavior so the term Behavior is used more than the term ‘Test’. BDD is part of Test Driven Development which focuses on behavior and not on tests.

According to Dan North, “I found the shift from thinking in tests to thinking in behavior so profound that I started to refer to TDD as BDD, or Behavior Driven Development.” TDD scrutinizes on how something will work and BDD scrutinizes on why should we build it at all.

BDD answers the following questions often faced by the developers −

Question Answer
Where to start? outside-in
What to test? User Stories
What not to test? anything else

These answers result in the story framework as follows −

Story Framework

As a [Role]

I want [Feature]

so that [Benefit]

Which means , ‘When a Feature is executed, the resulting Benefitis to the Person playing the Role.’

BDD further answers the following questions −

Question Answer
How much to test in one go? very little-focused
What to call their tests? sentence template
How to understand why a test fails documentation

These answers result in the Example framework as follows −

Example Framework

Given some initial context,

When an event occurs,

Then ensure some outcomes.

This means, ‘Starting with the initial context, when a particular event happens, we know what the outcomes should be.’

The above example describes about the expected behavior of the system. The examples are mainly created to explain different scenarios of the system.

Story and Scenarios

Let’s see the following example by Dan North about an ATM system.


As a customer,

I want to withdraw cash from an ATM,

so that I do not have to wait in line at the bank.


There are two possible scenarios for this story.

Scenario 1 − Account is in credit

Given the account is in credit

And the card is valid

And the dispenser contains cash

When the customer requests cash

Then ensure the account is debited

And ensure cash is dispensed

And ensure the card is returned

Scenario 2 − Account is overdrawn past the overdraft limit

Given the account is overdrawn

And the card is valid

When the customer requests cash

Then ensure a rejection message is displayed

And ensure cash is not dispensed

And ensure the card is returned

The above event will be similar in both the scenarios, but in different context. So the outcomes are different.

Development Cycle

The Development Cycle for BDD is an outside-in approach.

Step 1 − Write a high-level (outside) business value example (using Cucumber or RSpec/Capybara) that goes red. (RSpec produces a BDD framework in the Ruby language)

Step 2 – Then write a lower-level (inside) RSpec example for the first step of implementation that goes red.

Step 3 – Now implement the minimum code to pass that lower-level example, see it go green.

Step 4 – Then write the next lower-level RSpec example pushing towards passing Step 1 that goes red.

Step 5 – Here repeat steps Step 3 and Step 4 until the high-level example in Step 1 goes green.

Note − The following points should be kept in mind −

  • Red/green state is a permission status.
  • oIncase if your low-level tests are in green, then you will have the permission to write new examples or refactor with available implementation. So you need not use that in the scenario of refactoring, add new functionality/flexibility.
  • If your low-level tests are red then you will have permission to write or change implementation code after turning the tests to go green. For this you need to resist the urge to write the code to pass your next test, which never used to implement features you may think are good.

Behavior Driven Development Related Tutorials

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Behavior Driven Development Topics