This document summarizes a presentation on Behavior Driven Development (BDD). It discusses how BDD is an evolution of test driven development that uses scenarios written in plain language to define tests. Common BDD tools like JBehave and Serenity are presented. The document concludes with tips for keeping BDD practices alive on projects by involving the whole team, using journeys instead of isolated tests, and maintaining open communication.
2. Agenda
• Intro
• TDD and BDD
• Tools
–JBehave
–Serenity
• How to Keep BDD Love Alive
3. A “little” bit about Rory
• Technology Evangelist at BBD
– www.bbd.co.za
• Organizer for Jozi-JUG and Joburg AWS User
Forum (AWS-Jozi)
• Not related to Tyrion Lannister
• Don’t do kids parties
4.
5. SENDER
Step 1: Make an appointment
“I would like to Dialogue about
something.
Is now OK?”
Step 2: The Send
“I feel…”, “I tell myself…”,
“My desire is…”
Step 3: The Summary
“You got it all”
RECEIVER
Step 1: Agree to the
appointment
“I’m available now”
Step 2: The Mirror and the
Check
I heard you say…, You said…
Step 3: The Summary
“Am I getting you? Did I get all
of that?”
6.
7. Agenda
• Intro
• TDD and BDD
• Tools
–JBehave
–Serenity
• How to Keep BDD Love Alive
8.
9. BDD is about having conversations
BDD should make it easy to create software
A scenario is an idea, not a promise
10. So BDD is…
• An evolution of Test Driven
Development
• Created by Dan North in 2003:
“Programmers wanted to know where to
start, what to test and what not to test,
how much to test in one go, what to call
their tests, and how to understand why a
test fails.”
14. Test Driven Development (TDD)
Kent Beck defines:
• Never write a single line of code unless you have a failing
automated test.
• Eliminate duplication.
• Red (Automated test fail)
• Green (test pass)
• Refactor (Clean the code)
RED
GREENREFACTOR
TDD
17. Agenda
• Intro
• TDD and BDD
• Tools
–JBehave
–Serenity
• How to Keep BDD Love Alive
18. JBehave
• Created by Dan North in 2003
• Original BDD framework
• Great Tooling and IDE plugins
• Uses Given/Then/When in plain text
• Decision tables
–we know you love excel
19. Write a Story
Given a shopping cart
When one item is added
Then the cart should have 1 items in it
…
20. Map Steps to Code
@Given("a shopping cart")
public void aCart() {
cart = new ShoppingCart();
}
@When("one item is added")
public void addAnItem() {
cart.getItems().add(new Item("Juice", Item.SHELF.TOP));
}
@Then("the cart should have $numberOfItems items in it")
public void checkItemsSaved(int numberOfItems) {
assertEquals(numberOfItems, cart.getItems().size());
}
25. Demo
Given a shopping cart
When there is help for a hard to reach item
Then help should give me that item
Examples:
|itemName|shelf|help
|Eggs|BOTTOM|true
|tabasco|MIDDLE|true
|Juice|TOP|false
29. Feature:
Rory
thinks
Add new todos
needs to be able to jot down actions he needs to do as he
of them
Scenario: Record a new todo action
to buy
for future use
Given Rory needs some milk
When Rory adds the todo action 'Bu
y
som
e
milk'
Then 'Buy some milk' should be recorded in his todo list
A goal
A task
@Steps ATodoUser rory;
@When(“^(?:.*) (?:adds|has added) the todo action '(.*)'$")
public void i_add_the_todo_action(String actionName) {
rory.adds_an_action_called(actionName);
} The task definition
TodoPage onTheTodoHomePage
; An interaction
@Step
public void adds_an_action_called(String actionName) {
onTheTodoHomePage.addAnActionCalled(actionName);
}
The Serenity layered architecture
30. Feature: Add new todos
I need to be able to jot down actions I need to do as fast as I think of them
Scenario:
Given I
Record a new todo action for future use
need to buy some milk
When I add the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in my todo list
Serenity documentation
31.
32. Demo Time!
Given I need to <definition1>
When I add the todo action "<action1>"
Then "<action1>" should be recorded in my todo list
Examples:
|definition1|action1
|buy some milk|Buy some milk
|buy some sugar|Buy some sugar
35. Actors have goals
Given Rory needs to buy some milk
When Rory adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
I’d like to be able to recall
all the things I need to do
Journey Pattern
36. Actors have abilities I can browse the web with my
browser
Journey Pattern
Actor rory = Actor.named(“Rory");
@Managed
WebDriver hisBrowser;
…
rory.can(BrowseTheWeb.with(hisBrowser));
37. I’ll add ‘Buy some milk’ to
my todo list
Actors perform tasks
Journey Pattern
@Steps
AddItem addATodoItem;
…
rory.attemptsTo(addATodoItem.called("Buy some milk"));
38. Actors may interact with the system to
perform these tasks
Type ‘Buy the milk’
Press ‘ENTER’
Journey Pattern
46. We have large BDD suites written in a Cucumber Clone
• They spend much of their life red
Customers don’t engage with our BDD suites
• And yet we spend a lot of time maintaining them
Our BDD suites are slow to run and increase the cost
of the “check-in dance”
• Developers start ignoring red results
• And we have to down tools to fix them
Developers don’t want to write them
• Because they can’t see the value return on their
effort
• They just want to build software
BDD Counselling
47. How to Keep BDD Alive
• Don’t Skip the conversation
• Involve the whole team
• Use Journeys not Events
• Accept you’ll still miss things
48. How to Keep BDD Love Alive
• Work on it - don’t rely on “magic”.
• “Its 50% your responsibility”
• Avoid
–Criticism
–Contempt
–Defensiveness
–Stonewalling
49.
50. What did We Learn?
• What is BDD
• Tools
–JBehave
–Serenity
• How to Keep BDD Love Alive
• Lookout!
–Shameless User Group Plug coming up…
51. AWS-JOZI - www.meetup.com/AWS-JOZI
New AWS centric User group
Top notch venues
Jozi-JUG - www.meetup.com/Jozi-JUG
2000 members
Sessions of +200 attendees
Conferences and monthly meetups
Venues rotate around Johannesburg
&
Self Social
Mentorship
Community
Culture
Experience
Relevance
Education
Career