Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Specification-By-Example with Gherkin

3,092 views

Published on

Presented at GoTo Night Zurich, June 12 2014

Many teams struggle with the implementation of user story acceptance criteria and establishing a shared understanding about the expected story outcomes. This results in missed stakeholder expectations and ad-hoc assumptions made by the team. High efforts for regression testing and the lack of a reliable documentation about the current system behavior are further problems resulting from an unstructured approach to define and validate acceptance criteria.
In this session, you will learn how specification-by-example addresses these problems and overall increases the level of clarity on the project end-to-end. The presentation will cover the theory and practical experience from real projects, with concrete implementation examples based on the Gherkin specification language, that can be used for automated specification validation (available for .NET, Java, Ruby, PHP, JavaScript).
You will leave this session with a fundamental understanding of specification-by-example and its benefits, as well as concrete pointers on how to get started using it in your own projects.

Published in: Technology, Business

Specification-By-Example with Gherkin

  1. 1. FROM STAKEHOLDER EXAMPLES TO LIVING DOCUMENTATION Specification-By-Example with Gherkin Christian Hassa - ch@techtalk.ch - Twitter: @chrishassa GoTo Night Zurich, June 12th 2014
  2. 2. 2 2000 2009 2010 2007 Scrum 1997 1992 2014
  3. 3. 7 User Story life-cycle Idea Need Problem
  4. 4. 8 Impact Mapping Story Mapping Specification-By-Example Why? Outcomes Specifications How? Acceptance Criteria Epics Deliverables Impacts earlier later User Activities User Stories Examples Goals Agile Product Ownership Code
  5. 5. 9 Evolving User Stories into Specifications
  6. 6. 10 Impact Mapping Story Mapping Specification-By-Example Why? Outcomes Specifications How? Acceptance Criteria Epics Deliverables Impacts earlier later User Activities User Stories Examples Goals Specifying user stories Code
  7. 7. 11 Why? Outcomes Specifications How? Epics Deliverables Impacts earlier later User Activities User Stories Goals Specifying user stories Code Reminder for a conversation
  8. 8. 12 Having a conversation … Register as “bart_bookworm” Go to “/catalog/search” Enter “ISBN-0955683610” Click “Search” Click “Add to Cart” Click “View Cart” Verify “Subtotal” is “$33.75” We would like to encourage new users to buy in our shop. Therefore we offer 10% discount for their first order. Original idea for the illustration: George Dinwiddie http://blog.gdinwidiee.com public void CalculateDiscount(Order order) { if (order.Customer.IsNew) order.FinalAmount = Math.Round(order.Total * 9/10); }
  9. 9. 13 Specification-By-Example Why? Outcomes Specifications How? Acceptance Criteria Epics Deliverables Impacts earlier later User Activities User Stories Examples Goals Establishing a shared understanding Code Bug reports Isolated, formalized examples
  10. 10. 14 Specification-by-Example Examples … • make abstract descriptions better understandable However … • examples are usually not formally exchanged or documented Brian Marick Examples Tests Requirements consist of describe verify fulfillment of
  11. 11. 15 Discussing acceptance criteria … Register as “bart_bookworm” Go to “/catalog/search” Enter “ISBN-0955683610” Click “Search” Click “Add to Cart” Click “View Cart” Verify “Subtotal” is “$33.75” We would like to encourage new users to buy in our shop. Therefore we offer 10% discount for their first order. Original idea for the illustration: George Dinwiddie http://blog.gdinwidiee.com public void CalculateDiscount(Order order) { if (order.Customer.IsNew) order.FinalAmount = Math.Round(order.Total * 9/10); }
  12. 12. 16 … illustrated with formalized examples Given the user has not ordered yet When the user adds a book with the price of EUR 37.5 into the shopping cart Then the shopping cart sub-total is EUR 33.75. Original idea for the illustration: George Dinwiddie http://blog.gdinwidiee.com We would like to encourage new users to buy in our shop. Therefore we offer 10% discount for their first order.
  13. 13. 17 Discover hidden assumptions Actually, this is not quite right: Books on sale should be excluded. Original idea for the illustration: George Dinwiddie http://blog.gdinwidiee.com
  14. 14. 18 Collaboration: 3 amigos “Happy Path” Technical feasability Exceptions, border cases Original idea for the illustration: George Dinwiddie http://blog.gdinwidiee.com
  15. 15. 19 Structuring the conversation
  16. 16. 20 Collecting Acceptance Criteria “I would try to put a book into the shopping cart …” “I would try to remove a book from the shopping cart…” “I’d check whether the shopping cart is empty, when I enter the shop …” Books can be added to shopping cart. Books can be removed from shopping cart. Shopping cart should be empty when entering the shop. ... ? … As a potential customer I want to collect books in a shopping cart So that I can order several books at once. “Imagine this story is already implemented: How would you verify it?” “I would try to add 1000 books to the shopping cart …”
  17. 17. 21 Exploration through examples Books in catalogue: Title Author Specification-By-Example Gojko Adzic Impact Mapping Gojko Adzic Explore It! Elisabeth Hendrickson Competitive Engineering Tom Gilb … I want to find books in the catalogue by author and title Search for … Books found … Spec Specification-By-Example Hend Explore It! et Explore It!, Competitive Engineering Context Action Assertion
  18. 18. 22 Key examples: Breaking the model Books in catalogue: Title Author Specification-By-Example Gojko Adzic Impact Mapping Gojko Adzic Explore It! Elisabeth Hendrickson Competitive Engineering Tom Gilb … I want to find books in the catalogue by author and title Search for … Books found … Spec Specification-By-Example Hend Explore It! et Explore It!, Competitive Engineering What happens, if I search for “Explore Specification”? Can I search for single characters, e.g. “e”? Is the number of search results limited, or paged? Is the search also performed in the sub-title of a book?
  19. 19. 23 UI wire frames, existing UI rules, key examples existing artifacts, samples Different kinds of examples
  20. 20. 24 Abstract acceptance criteria As a shop visitor I want to collect books in my shopping basket so that I can purchase multiple books at once. Books can be added to the shopping basket Books can be removed from the shopping basket Shopping basket is initially empty The same book can be added multiple times to the shopping basket
  21. 21. 25 Examples in Gherkin As a shop visitor I want to collect books in my shopping basket so that I can purchase multiple books at once. Books can be added to the shopping basket Given my shopping basket is empty When I add the book “Harry Potter” to my shopping basket Then my shopping basket should contain 1 copy of “Harry Potter”
  22. 22. 26 As a shop visitor I want to collect books in my shopping basket so that I can purchase multiple books at once. Books can be added to the shopping basket Examples in Gherkin Given my shopping basket contains 1 copy of “Harry Potter” When I add the book “Harry Potter” to my shopping basket Then my shopping basket should contain 2 copies of “Harry Potter” The same book can be added multiple times to the shopping basket
  23. 23. 27 The same book can be added multiple times to the shopping basket Structure of examples Given my shopping basket contains 1 copy of “Harry Potter” When I add the book “Harry Potter” to my shopping basket Then my shopping basket should contain 2 copies of “Harry Potter” Title: Describes intention/abstract acceptance criterion Arrange: Context, describes state of the system Act: Execution of the feature Assert: Assertion of observable behaviour And I should see the warning: “Book already existed in basket” Triple-A constraint “Checks” Chaining up steps
  24. 24. 28 Purpose of the examples • Shared understanding: acceptance criteria • Documentation: system details • Regression-tests: violated specifications
  25. 25. 29 Automated continuous validation Given my shopping basket contains 1 copy of “Harry Potter” When I add the book “Harry Potter” to my shopping basket Then my shopping basket should contain 2 copies of “Harry Potter” System „Step Definitions“ are binding individual steps to an automatable interface of the application. Automatable interface UI Automation Automation does not necessarily have to bind to the UI. Automatability of system is supported/evolving with development.
  26. 26. 30 Demo http://www.specflow.org Gherkin automation for .NET • Visual Studio plugin (VS-Gallery) • NuGet Package
  27. 27. 32 Booking system
  28. 28. 33 Payroll calculation
  29. 29. 34 eVoting system
  30. 30. 35 Examples in Excel
  31. 31. 36 Business readable team flow with ATDD
  32. 32. 37 Tasks are not business readable Create bookings for a fixed time loop on
  33. 33. 38 … but scenarios (AC) are
  34. 34. 39 ATDD cycle Write a failing unit test Make the test pass Refactor Write a failing acceptance test Deploy and measure impact Refine feature, if needed (new user story) break down units extend systemUser Story AC/Scenario 1 AC/Scenario 2 AC/Scenario … AC/Scenario n modify system Expected impact
  35. 35. 40 Business readable progress In Progress
  36. 36. 41 Current sprint report: all sprint scenarios
  37. 37. 42 Starting with first scenario (AC)
  38. 38. 43 Finishing the first scenario (AC)
  39. 39. 44 Progressing scenario after scenario
  40. 40. 45 Progressing scenario after scenario
  41. 41. 46 Progressing scenario after scenario
  42. 42. 47 Implementing user stories in parallel
  43. 43. 48 First user story ready for testing
  44. 44. 49 Testing can start even earlier
  45. 45. 50 Already done work can break again
  46. 46. 51 Already done work can break again
  47. 47. 52 See what is temporarily not working
  48. 48. 53 Living documentation
  49. 49. 54 Living documentation Drill into Details (Gherkin scenarios) Overview (Story Map)
  50. 50. 55 User Stories vs. Features Product/Sprint Backlog User Story 1 AccCrit 1 AccCrit 2 User Story 2 AccCrit 3 AccCrit 4 Living Documentation Feature 1 AccCrit 1 AccCrit 2 Feature n AccCrit 4 AccCrit m User Story n AccCrit 5 AccCrit m AccCrit 3 AccCrit 5 „Done“ • Future options of the system • Organized/refined according to priority, value, effort, risk, ... • Next possible increments of the product (units of work) • Current state of the system • Organized/refined for functional overview • Versioned and maintained together with source code
  51. 51. 56 Getting started with Specification-By-Example
  52. 52. 57 Start with the conversation • What happens when … ? • What would you try out … ? • Discuss based on concrete examples
  53. 53. 58 Grow your team’s skills • (Acceptance) Test Driven Development • Test Automation Pyramid • Exploratory Testing
  54. 54. 59 Decide for an automation tool Gherkin tools available for Ruby, Java, .NET, JavaScript, PHP, … www.specflow.org www.cukes.info Other ATDD tools like: JBehave, Fitnesse, Robotframework, Concordion, …
  55. 55. 60 Treat test automation as a first class citizen • Emerging architecture • Refactoring • Definition of Done
  56. 56. 61 Books to read Gojko Adzic Bridiging the Communication Gap Gojko Adzic Specification by Example Elisabeth Hendrickson Explore IT!
  57. 57. Coaching
  58. 58. Coaching
  59. 59. 65
  60. 60. 69 Christian Hassa: ch@techtalk.ch - @chrishassa

×