BDD

1,677 views

Published on

BDD is an emerging development methodology and this session provides an introduction to it.

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

BDD

  1. 1. Behaviour Driven Development
  2. 2. BDD is a development methodology. BDD is not something new – it is an evolution
  3. 3. No real spec No formal testing
  4. 4. Functional Spec Limited Formal Testing
  5. 5. Functional Spec Unit Tests
  6. 6. <ul><li>“ That wasn’t covered by a test” </li></ul><ul><li>“ The code works already, so why write the test” </li></ul>
  7. 7. Functional Spec TDD
  8. 8. <ul><li>Test Driven Development </li></ul><ul><li>Code Unit Tests First </li></ul><ul><li>Red – Green – Refactor </li></ul><ul><li>Better designs </li></ul>
  9. 9. <ul><li>Testing things that may be changed or irrelevant later </li></ul><ul><li>Difficult to understand impact </li></ul><ul><li>Computer mouse or real mouse? </li></ul>
  10. 10. Functional Spec BDD
  11. 11. <ul><li>Behaviour Driven Development </li></ul><ul><li>Coined by Dan North in March 2006 </li></ul><ul><ul><li>http://blog.dannorth.net/introducing-bdd/ </li></ul></ul>
  12. 12. Waterfall, 13% Iterative, 21% Agile, 35% Source: Forrester/Dr. Dobb’s Global Developer Technographics Survey, Q3 2009
  13. 14. <ul><li>Domain Specific Language </li></ul><ul><li>Gherkin based </li></ul><ul><ul><ul><ul><li>Feature Big idea </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Business case for feature </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Scenario testable part of feature </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Given some input </li></ul></ul></ul></ul><ul><ul><ul><ul><li>When I am am </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Then some output </li></ul></ul></ul></ul>
  14. 15. <ul><li>Feature pressing a key, displays the number </li></ul><ul><li>It is an accepted UI standard to display the numbers on key press so we should do likewise. </li></ul><ul><li>Scenario Pressing 1 puts it in the memory buffer </li></ul><ul><li>Given button input of 1 </li></ul><ul><li>When I am user </li></ul><ul><li>Then buffer should contain 1 </li></ul><ul><li>Scenario Display shows what is in memory buffer </li></ul><ul><li>Given memory buffer of 1356 </li></ul><ul><li>When I am a user </li></ul><ul><li>Then display should show 1356 </li></ul>
  15. 16. <ul><li>Feature pressing a key, displays the number </li></ul><ul><li>It is an accepted UI standard to display the numbers on key press so we should do likewise. </li></ul><ul><li>Scenario Pressing 1 puts it in the memory buffer </li></ul><ul><li>Given button input of 1 </li></ul><ul><li>And memory buffer is empty </li></ul><ul><li>When I am user </li></ul><ul><li>Then buffer should contain 1 </li></ul><ul><li>Scenario Display shows what is in memory buffer </li></ul><ul><li>Given memory buffer of 1356 </li></ul><ul><li>When always </li></ul><ul><li>Then display should show 1356 </li></ul>
  16. 17. <ul><li>Scenario Add a new employee to the system with all values correct should add the employee </li></ul><ul><li>Given Employee name is Robert MacLean </li></ul><ul><li>And Employee number is 00001 </li></ul><ul><li>And Employee Start date is 1 January 2008 </li></ul><ul><li>And Employee with employee number 00001 is not in data store </li></ul><ul><li>When I am a user </li></ul><ul><li>Then the employee is added successfully </li></ul><ul><li>And verify the employee status is Employed </li></ul><ul><li>And verify the employee name is Robert MacLean </li></ul><ul><li>And verify the employee number is 00001 </li></ul><ul><li>And verify the employee start date is 1 January 2008 </li></ul><ul><li>and verify the employee end date is empty </li></ul>
  17. 18. From http://www.slideshare.net/giordano/bdd-tdd-and-beyond-the-infinite
  18. 19. <ul><li>Title (one line describing the story) </li></ul><ul><li>Narrative: </li></ul><ul><li>As a [role] </li></ul><ul><li>I want [feature] </li></ul><ul><li>So that [benefit] </li></ul><ul><li>Acceptance Criteria: </li></ul><ul><li>Scenarios… </li></ul>
  19. 20. <ul><li>Common language understood by all stakeholders </li></ul><ul><li>Sets out logically what is needed </li></ul><ul><li>Familiar to user stories </li></ul><ul><li>Not a replacement to functional specs, but an addition </li></ul><ul><li>Your thoughts? </li></ul>
  20. 21. <ul><li>Small piece of code to test API </li></ul><ul><li>Asserts result </li></ul><ul><li>Unit test framework </li></ul>[ TestClass ] public   class   TestAdder { [ TestMethod ] public   void  testSum() { Calc  calc =  new   Calc ();    Assert .IsEqual(calc.Add(1, 1), 2); } } 
  21. 22. <ul><li>Small piece of code to action step </li></ul><ul><li>Assert results </li></ul><ul><li>Unit test framework </li></ul><ul><ul><li>Need specialised framework </li></ul></ul><ul><ul><li>Modify the code of an existing framework </li></ul></ul>
  22. 24. <ul><li>Writing specs is hard work  </li></ul><ul><li>Writing stories helped find inconsistencies in spec </li></ul><ul><li>Writing tests was easy for 80% of them </li></ul><ul><li>DSL was relatively easy </li></ul><ul><li>Story needed some evolution </li></ul><ul><li>Code is really clean </li></ul>
  23. 25. <ul><li>Scenario Add a new employee to the system with all values correct should add the employee </li></ul><ul><li>Given Employee name is Robert MacLean And Employee number is 00001 </li></ul><ul><li>And Start date is 1 January 2008 </li></ul><ul><li>And Employee with employee number 00001 is not in data store When added by a user Then the employee is added successfully  And the employee status is Employeed  And verify the employee name is Robert MacLean And verify the employee number is 00001  And the start date is 1 January 2008 </li></ul><ul><li>Scenario Add a new employee to the system with all values correct should add the employee Given Employee name is Robert MacLean  And Employee number is 00001   And Employee Start date is 1 January 2008  And Employee with employee number 00001 I not in data store When I am a user Then the employee is added successfully And verify the employee status is Employeed And verify the employee name is Robert MacLean And verify the employee number is 00001   And verify the employee start date is 1 January 2008 and verify the employee end date is empty </li></ul>
  24. 26. <ul><li>Overall maturity of tools is low </li></ul><ul><li>Java, Python & Ruby are strongest </li></ul><ul><li>C++ &. NET tools exist but immature </li></ul><ul><li>Unable to find any VB tools </li></ul><ul><li>Commercial tooling & training is very limited </li></ul>

×