BDD
Behaviour Driven Development
Agenda
Introduction of BDD
History of BDD
Why BDD
Setup Environment And Pre-requisites
BDD Concept
BDD Annotations
Practical Examples
BDD - Introduction
Test-driven development focuses on the developers opinion on how parts of the
software should work.
Behavior-driven development focuses on the users opinion on how they want your
application to behave.
BDD Overview
1. Write Story
2. Map Steps to Java
3. Configure Stories
4. Run Stories
5. View Reports
BDD - History
2003: agiledox, the ancestor of BDD, is a tool generating technical documentation
automatically from JUnit tests, written by Chris Stevenson
2004: in order to test his hypotheses about de-emphasizing "test" terminology in favor
of "behavior", Dan North releases Jbehave
2006: in collaboration with Chris Matts, North proposes the given-when-then canvas to
expand the scope of BDD to business analysis and documents the approach in
"Introducing BDD
2006-2009: several new tools are released confirming the community's investment in
BDD, such as RSpec or more recently, Cucumber and GivWenZen
Why BDD?
In TDD whole bunch of test cases fails because of change of implementation.
In BDD officially test cases are not broken as user change the behavior of the
application.
BDD locks the behavior of the application instead of locking the implementation.
Why BDD? - Sorting
Bubble sort
Selection sort
Given a list of numbers
Insertion sort
When I sort the list
Shell sort
Then the list will be in numerical order
Comb sort
Merge sort
Quick sort
BDD - Concept
Stories
BDD revolves around the concept of a Story, which represents an automatically
executable increment of business functionality.
Scenarios
At its core a Story comprises of one or more Scenarios, each of which represents a
concrete example of the behaviour of the system.
Steps
Each Scenario comprises of a number of executable steps. These Steps can be of
three types: Given, When and Then are also called BDD Keywords
BDD Jbehave Setup Environment And Pre-requisites
Add following dependencies in pom.xml file
Pre-requisite Technologies for Jbehave Framework
1. Spring
2. Maven
BDD Jbehave Annotations
Stories Annotations
The @BeforeStories and @AfterStories annotations allow the corresponding
methods to be executed before and after a collection of stories
Story Annotations
The @BeforeStory and @AfterStory annotations allow the corresponding methods
to be executed before and after each story
Scenario Annotations
The @BeforeScenario and @AfterScenario annotations allow the corresponding
methods to be executed before and after each scenario
BDD - Jbehave Annotations
Step Annotations
1. @Given What has happened before
2. @When - What actions the user performs
3. @Then - The desired outcome for the user
4. @Alias Execute same method with the different step
@When("the item price is $price")
@Alias("the item price becomes $price") // single alias
public void theItemPriceIs(double price) {}
5. @Aliases - Execute same method with the different steps
@When("the item price is $price")
@Aliases(values={"the item price becomes $price"
"the item price equals to $price"}) // multiple aliases
public void theItemPriceIs(double price) {}
6. @Pending - Annotation allows steps developers to mark any step method as
pending. E.g. the step has yet to be implemented.
@When("the item price is $price")
@Pending
BDD - Jbehave Annotations
Parameter Annotation
1. @Named - Parameter annotations are used in parameter injection.
@Given("a stock of symbol $symbol and a threshold of $threshold")
public void aStock(@Named("symbol") String aSymbol, @Named("threshold") double aThreshold) {}
Configuration Annotations
1. @AsParameterConverter
2. @Configure
3. @UsingEmbedder
4. @UsingSteps
5. @UsingGuice
6. @UsingNeedle
7. @NeedleInjectionProvider
8. @UsingPico
9. @UsingSpring
BDD For Developers
Lets go through Practical Example
BDD For Testers
Lets go through Practical Example
References
BDD -
http://jbehave.org/reference/stable/index.html
Thank You