Your SlideShare is downloading. ×
0
BehaviorDrivenDevelopmentManodnya LeleBen Maynard
About Litle & Co.• Litle & Co. is a leading financial technology company• One of the largest, private, non-bank proprietar...
Outline•   What is BDD?•   History•   Why not TDD?•   The Story•   Tools: Compare and Contrast•   Comments and Questions
What is BDD?BDD can turn an idea for a requirement into  implemented, tested, production-ready code simply  and effectivel...
What is BDD?BDD can turn an idea for a requirement into  implemented, tested, production-ready code simply  and effectivel...
What is BDD?BDD can turn an idea for a requirement into  implemented, tested, production-ready code simply  and effectivel...
What is BDD?BDD can turn an idea for a requirement into  implemented, tested, production-ready code simply  and effectivel...
History1999   Test First   Development                 2003                    Behavior Driven                    Developm...
History1999   Test First   Development                 2003                    Behavior Driven                    Developm...
HistoryKent Beck   Dan North
Why not TDD?BAs / Program Managers   Techies
Why not TDD?BAs / Program Managers    Techies• Requirements docs not  technical enough
Why not TDD?BAs / Program Managers    Techies• Requirements docs not   • Test cases and unit tests  technical enough      ...
Why not TDD?
Why not TDD?     BDDGiven… When… Then…
Why not TDD?TDD      BDD
Why not TDD?TDDBuilding the thing right                   BDD
Why not TDD?TDDBuilding the thing right                   BDD                   Building the right thing
BDD:The Story
BDD: The Story• A way to describe the requirement such that everyone           the business folks,           the analyst, ...
BDD: The Story• The title should describe an activity     Describes actual behavior by a user of the system.• The narrativ...
BDD: The StoryTitle        Easier user experience with online siteNarrative     As a(n) active, participating member of my...
BDD Tool Overview
Motivating ExampleFizzBuzz• Simple program that outputs a number and expects  the player to guess which word applies:   – ...
jbehavehttp://jbehave.org
How to write a BDD test in jbehave• Write the story in a file with a <story_name>.story  name• Create the implementation i...
jbehave Story• Story: Play fizz-buzz                      • Examples:    As a math game player                       |valu...
jbehave Test Codepublic class PlayFizzBuzzSteps            @Then("I should get a <display>"){                             ...
jbehave Runnerpublic class PlayFizzBuzz extends JUnitStory {    public PlayFizzBuzz()    {      addSteps(new InstanceSteps...
easybhttp://easyb.org
FizzBuzz with easybnarrative "while playing fizz-buzz", {    as_a "fizz-buzz player"    i_want "to automate my responses" ...
Cucumberhttp://cukes.info
Cucumber FeatureFeature: Play Fizz Buzz  As a math game player  I would like to play fizz-buzz  So that I can learn how to...
Cucumber Test CodeGiven /a fizz-buzz player/ do |n|  @fb = FizzerBuzzer.newendWhen /I ask to fizz-buzz for 3/ do |op| @res...
Compare and ContrastCriteria            jbehave           easyb             CucumberLanguage written    Java              ...
Criteria            jbehave            easyb                CucumberPending tests       Supported          Supported      ...
SummaryGiven that you have heard this presentation And discovered that BDD is really funWhen you are thinking about testin...
MaterialsReady-made BDD project (Sualeh Fatehi)   http://code.google.com/p/test-fizzbuzz/
Upcoming SlideShare
Loading in...5
×

Behavior Driven Development: An Overview

2,278

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,278
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
103
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Behavior Driven Development: An Overview"

  1. 1. BehaviorDrivenDevelopmentManodnya LeleBen Maynard
  2. 2. About Litle & Co.• Litle & Co. is a leading financial technology company• One of the largest, private, non-bank proprietary processing platforms serving the Card-not-Present marketplace• Specific expertise in Card-not-Present transactions, deep knowledge of Best Practices, Card Association Regulations, PCI and Data Security requirements• Litle Vault is the 2011 Stevie Award Winner in New Product & Services (Web/IVR) category
  3. 3. Outline• What is BDD?• History• Why not TDD?• The Story• Tools: Compare and Contrast• Comments and Questions
  4. 4. What is BDD?BDD can turn an idea for a requirement into implemented, tested, production-ready code simply and effectively, as long as the requirement is specific enough that everyone knows what’s going on. -Dan North
  5. 5. What is BDD?BDD can turn an idea for a requirement into implemented, tested, production-ready code simply and effectively, as long as the requirement is specific enough that everyone knows what’s going on. -Dan North
  6. 6. What is BDD?BDD can turn an idea for a requirement into implemented, tested, production-ready code simply and effectively, as long as the requirement is specific enough that everyone knows what’s going on. -Dan North
  7. 7. What is BDD?BDD can turn an idea for a requirement into implemented, tested, production-ready code simply and effectively, as long as the requirement is specific enough that everyone knows what’s going on. -Dan North
  8. 8. History1999 Test First Development 2003 Behavior Driven Development
  9. 9. History1999 Test First Development 2003 Behavior Driven Development Kent Beck
  10. 10. HistoryKent Beck Dan North
  11. 11. Why not TDD?BAs / Program Managers Techies
  12. 12. Why not TDD?BAs / Program Managers Techies• Requirements docs not technical enough
  13. 13. Why not TDD?BAs / Program Managers Techies• Requirements docs not • Test cases and unit tests technical enough too technical
  14. 14. Why not TDD?
  15. 15. Why not TDD? BDDGiven… When… Then…
  16. 16. Why not TDD?TDD BDD
  17. 17. Why not TDD?TDDBuilding the thing right BDD
  18. 18. Why not TDD?TDDBuilding the thing right BDD Building the right thing
  19. 19. BDD:The Story
  20. 20. BDD: The Story• A way to describe the requirement such that everyone the business folks, the analyst, the developer, the tester, and others has a common understanding of the scope of the work.• A description of a requirement and its business benefit, and a set of criteria by which we all agree that it is “done”.• Remember: Given… When… Then…
  21. 21. BDD: The Story• The title should describe an activity Describes actual behavior by a user of the system.• The narrative should include a role, a feature and a benefit “As a [role] I want [feature] so that [benefit]“• The scenario should be described in terms of givens, events and outcomes Given… When… Then…
  22. 22. BDD: The StoryTitle Easier user experience with online siteNarrative As a(n) active, participating member of my company I want a better online website So that users can easily use and purchase on our website Scenario 1: Smooth Checkout Process Scenario 2: Better Site Uptime Given our world class web sales app Given that a potential buyer And items in my shopping cart When a user enters our URL into a browser When a user clicks “checkout” Then the site will be available over 99.97% Then the user will move through checkout of the time with a maximum of two page clicks And maintain an https session with our site
  23. 23. BDD Tool Overview
  24. 24. Motivating ExampleFizzBuzz• Simple program that outputs a number and expects the player to guess which word applies: – Divisible by 3: “Fizz” – Divisible by 5: “Buzz” – Divisible by 3 and 5: “FizzBuzz”
  25. 25. jbehavehttp://jbehave.org
  26. 26. How to write a BDD test in jbehave• Write the story in a file with a <story_name>.story name• Create the implementation in Java in a class named <StoryName>Steps.java• Create an Runner, extending JUnitStory to link the story to the implementation• Runner also can specify other details such as output formats
  27. 27. jbehave Story• Story: Play fizz-buzz • Examples: As a math game player |value|display| I would like to play fizz-buzz |1|1| So that I can learn how to calculate |2|2| multiples |3|fizz| Scenario: When to fizz |4|4| Given a fizz-buzz player |5|buzz| When I ask to fizz-buzz for 3 |6|fizz| Then I should get a fizz |7|7| |8|8| Scenario: When to fizz-buzz |9|fizz| Given a fizz-buzz player |10|buzz| When I ask to fizz-buzz for <value> Then I should get a <display> |15|fizz-buzz| |30|fizz-buzz|
  28. 28. jbehave Test Codepublic class PlayFizzBuzzSteps @Then("I should get a <display>"){ @Alias("I should get a $display") private FizzBuzzer fb; public void isBuzz(@Named("display") final private String answer; String display) {@Given("a fizz-buzz player") assertThat(answer, is(display));public void givenAFizzBuzzPlayer() }{ fb = new FizzBuzzer(3, 5);}@When("I ask to fizz-buzz for <value>")@Alias("I ask to fizz-buzz for $value")public void answer(@Named("value") final int value){ answer = fb.answer(value); }
  29. 29. jbehave Runnerpublic class PlayFizzBuzz extends JUnitStory { public PlayFizzBuzz() { addSteps(new InstanceStepsFactory(configuration(), new PlayFizzBuzzSteps()) .createCandidateSteps()); } @Override public Configuration configuration() { return super.configuration() .useStoryReporterBuilder(new StoryReporterBuilder().withFormats(Format.CONSOLE, Format.TXT, Format.HTML)); }}
  30. 30. easybhttp://easyb.org
  31. 31. FizzBuzz with easybnarrative "while playing fizz-buzz", { as_a "fizz-buzz player" i_want "to automate my responses" so_that "i always win"} scenario "fizzing", { given "a fizz-buzz player", { fb = new sf.projects.fizzbuzz.FizzBuzzer(3, 5) } when "3", { display = fb.answer(3); } then "should fizz", { display.shouldBe "fizz" }}
  32. 32. Cucumberhttp://cukes.info
  33. 33. Cucumber FeatureFeature: Play Fizz Buzz As a math game player I would like to play fizz-buzz So that I can learn how to calculate multiplesScenario: When to fizz Given a fizz-buzz player When I ask to fizz-buzz for 3 Then I should get a fizz
  34. 34. Cucumber Test CodeGiven /a fizz-buzz player/ do |n| @fb = FizzerBuzzer.newendWhen /I ask to fizz-buzz for 3/ do |op| @result = @fb.answer opendThen /I should get a fizz/ do |result| @result.should == result.to_fend
  35. 35. Compare and ContrastCriteria jbehave easyb CucumberLanguage written Java Groovy RubyinLanguages Any language on Any language on Ruby or (withsupported the JVM the JVM Cuke4Duke) JavaWriting the story Separate files Single file Separate filesand testRunning tests Commandline, Ant, Commandline, Ant, Commandline or Maven, IDEs like Maven, IDEs like (with Cuke4Duke) Eclipse, JUnit Eclipse, JUnit Ant, Maven, IDEs like Eclipse
  36. 36. Criteria jbehave easyb CucumberPending tests Supported Supported SupportedfeatureRunning multiple Supported Supported SupportedtestsAssertion feature Can use Hamcrest Uses ‘ensure’ Uses Ruby matchers for syntax, similar to framework assertion assertInstallation Easy Easy FairDocumentation Good Extremely good No documentationsupport but good community supportYear of inception 2003 2009 2008Author Dan North Andy Glover Aslak Hellesøy
  37. 37. SummaryGiven that you have heard this presentation And discovered that BDD is really funWhen you are thinking about testing strategiesThen you should give BDD a chance!• Questions /Comments are welcome….• Contacts – Ben Maynard: bmaynard@litle.com – Manodnya Lele: mlele@litle.com
  38. 38. MaterialsReady-made BDD project (Sualeh Fatehi) http://code.google.com/p/test-fizzbuzz/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×