Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BDD Live

BDD Live

Rough Cut

arunsark

July 02, 2012
Tweet

Other Decks in Technology

Transcript

  1. www.ostryalabs.com 3 Test Driven Development  Think: Figure out what

    test will best move your code towards completion.  Red: Write a very small amount of test code. Only a few lines... usually no more than five. Run the tests and watch the new test fail.  Green: Write a very small amount of production code. Run the tests and watch them pass. Don't worry much about elegance and design purity.
  2. www.ostryalabs.com 4 Test Driven Development  Refactor: Now that your

    tests are passing, you can make changes without worrying about breaking anything. Look for duplication and other "code smells." If you see something that doesn't look right, but you're not sure how to fix it, that's okay.  Repeat: Do it again. You'll repeat this cycle dozens of times in an hour.
  3. www.ostryalabs.com 5 Test Driven Development ”To vouch this, is no

    proof, Without more wider and more overt test” —Othello, Act 1 Scene 3 William Shakespeare  is less about testing  is more about design  results in Clean Code That Works  is more addictive than caffeine!  leaves you Test Infected
  4. www.ostryalabs.com 6 Limitations of TDD  Developers tend to think

    TDD as tool to deliver high-quality code to testers  Tests tend to focus on internal of an Object  Testing what an object is rather than what the object does
  5. www.ostryalabs.com 7 The Crux of BDD It's all Behavior! 

    changes how you think about programming  Focus shifts to interactions between  people and systems  objects  Focus moves away from structure of objects, and that is how it should be!
  6. www.ostryalabs.com 8 Genesis of BDD  Dave Astels, in 2005,

    wrote the seminal post: A New Look at Test Driven Development  Stop thinking in terms of tests  Uncle Bob Martin: “Specification, not Verification”  Verification or tests just ensure code works  Specification defines what code ought to do
  7. www.ostryalabs.com 9 Genesis of BDD  In March 2006, Dan

    North wrote the seminal blog post Introducing BDD  He said many coders were confused about  where to start  what to test  what not to test  how much to test  what to call the tests  how to understand why a test fails
  8. www.ostryalabs.com 10 Genesis of BDD  Dan North got inspired

    by agiledox tool from Chris Stevenson for Java:
  9. www.ostryalabs.com 11 Genesis of BDD  Dan North proposed: 

    Test method names should be sentences  Simple sentences keep test methods focused  Expressive test names help when a test fails  “Behaviour” is a more useful word than “Test”
  10. www.ostryalabs.com 12 Genesis of BDD  Dan North proposed: 

    Test method names should be sentences  Simple sentences keep test methods focused  Expressive test names help when a test fails  “Behaviour” is a more useful word than “Test”
  11. www.ostryalabs.com 13 Genesis of BDD  Another source of inspiration

    was Domain Driven Design by Eric Evans  ”model a system using a ubiquitous language based on the business domain, so that the business vocabulary permeates right into the codebase.”  BDD gives us that ubiquitous language for analysis
  12. www.ostryalabs.com 14 BDD: Features  Inspired by this Connextra story

    format:  As a [X]  I want [Y]  so that [Z]  A story is interchangeably called a feature  But, a feature can be broken down into stories  It helps to distinguish between a feature and a story
  13. www.ostryalabs.com 15 Alternate Feature format  A variant of Connextra

    format:  In order to [Z] # Z is usually a benefit  As a [X]  I want [Y]  This is fast becoming the popular format  Subtle shift in emphasis by putting benefit first  Helps keep the focus on the outcome  ...and not on the detail of the feature
  14. www.ostryalabs.com 16 A sample Feature  Title: Customer withdraws cash

     As a customer,  I want to withdraw cash from an ATM  so that I don’t have to wait in line at the bank.
  15. www.ostryalabs.com 17 Feature using the Alternate format  Title: Customer

    withdraws cash  In order to not wait in line at the bank,  As a customer,  I want to withdraw cash from an ATM
  16. www.ostryalabs.com 18 BDD: Scenarios  Scenarios describe the acceptance criteria

     Given some initial context,  When an event occurs,  Then ensure some outcomes.  Given/When/Then – The BDD triad Features and Scenarios help nail the requirements as well as the acceptance criteria
  17. www.ostryalabs.com 19 A sample Scenario  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
  18. www.ostryalabs.com 20 Another sample Scenario  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
  19. www.ostryalabs.com 21 Another sample Scenario  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
  20. www.ostryalabs.com 22 The Principles of BDD  Enough is Enough

     Upfront planning, analysis and design all have a diminishing return  We shouldn't do less than we need to get started  But... any more than that is wasted effort!  Deliver stakeholder value  Do only things that deliver value  Or that increases your ability to deliver value  It's all behavior
  21. www.ostryalabs.com 25 The history of Cucumber  Dan North ported

    JBehave to Ruby as RBehave and it was merged into RSpec as Story Runner  In 2008, Aslak Hellesøy rewrote Story Runner and called it Cucumber as suggested by his fiancée  His plan was to merge it back into RSpec  But Cucumber has seeds and it sprouted!  It supports many languages now
  22. www.ostryalabs.com 26 Not just Ruby  Cucumber works with Java

     Cucumber works with .Net  Cucumber JVM a pure Java implementation of Cucumber relased in Apr 2012  Supports all JVM languages
  23. www.ostryalabs.com 30 Advantage BDD  Discover the ubiquitous language to

    use within a team  Happy Side Effects  Automated Acceptance Testing  Living Documentation