TDD, ATDD and BDD
TDD : Test Driven Development
Advantages of TDD
The benefits or advantages of Test Driven Development are −
● The developer needs to understand first, what the desired result should be and how to
test it before creating the code.
● The code for a component is finished only when the test passes and the code is
refactored. This ensures testing and refactoring before the developer moves on to the
next test.
● As the suite of Unit tests is run after each refactoring, feedback that each component is
still working is constant.
● The Unit tests act as living documentation that is always up to the data.
● If a defect is found, the developer creates a test to reveal that defect and then modify
the code so that the test passes and the defect is fixed. This reduces the debugging
time. All the other tests are also run and when they pass, it ensures that the existing
functionality is not broken
ATDD:Acceptance Test Driven Development
Acceptance Test Driven Development (ATDD) defines Acceptance Criteria and Acceptance
Tests during the creation of User Stories, early in development. ATDD focuses on the
communication and common understanding among the customers, developers and the testers.
The Key practices in ATDD are as follows −
● Discuss real-world scenarios to build a shared understanding of the domain.
● Use those scenarios to arrive at acceptance criteria.
● Automate Acceptance tests.
● Focus the development on those tests.
● Use the tests as a live specification to facilitate change.
The benefits of using ATDD are as follows −
● Requirements are unambiguous and without functional gaps.
● Others understand the special cases that the developers foresee.
● The Acceptance tests guide the development.
BDD (Behaviour Driven Development)
BDD is a process designed to aid the management and the delivery of software management
projects by improving communication between engineers and business professionals. In so
doing, BDD ensures all development projects remain focused on delivering what the business
actually needs while meeting all the requirements of the user.
Behavior Driven Development (BDD) is a software development process that originally emerged
from Test Driven Development (TDD). BDD uses examples to illustrate the behavior of the
system that are written in a readable and understandable language for everyone involved in the
development.
BDD Model :
Story Framework:
As a [Role]
I want [Feature]
so that [Benefit]
This means, ‘When a Feature is executed, the resulting Benefit is to the Person playing the
Role.’
Example Scenarios:
As a customer,
I want to withdraw cash from an ATM,
so that I do not have to wait in line at the bank.
Scenarios
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 event is same in both the scenarios, but the context is different. Hence, the outcomes are
different.
Test Driven Development (TDD) Behaviour Driven Development (BDD)
TDD = Test Case-> Code to Pass-> refactor BDD = TDD + Something More (Behaviour)
Focus on Implementation Aspects Focus on Behavioural Aspects
Transparency factor might be missing Transparency between user expectations and
developers tests
BDD Tools available in Market
Cucumber
JDave
JBehave
Concordion
BeanSpec
Specflow etc..
Cucumber:
Cucumber is a free tool for executable specifications used globally. Cucumber lets the software
development teams describe how software should behave in plain text. The text is written in a
business-readable, domain-specific language and serves as documentation, automated tests
and development-aid, all rolled into one format. You can use over forty different spoken
languages (English, Chinese, etc.) with Cucumber.
Cucumber – Key Features
The key features of Cucumber are as follows −
● Cucumber can be used for Executable Specifications, Test Automation and Living
Documentation.
● Cucumber works with Ruby, Java, NET, Flex or web applications written in any
language.
● Cucumber supports more succinct Tests in Tables - similar to what FIT does.
● Cucumber has revolutionized the Software Development Life Cycle by melding
requirements, automated testing and documentation into a cohesive one: plain text
executable specifications that validate the software.
Working Cucumber with Selenium:
● Downloading the required jar files from Maven Repository
● Understanding Feature File for writing features and scenarios using the keywords
Given, When, Then etc.