Specification-By-Example with Gherkin

7,521 views
7,348 views

Published on

Presentation held on Swiss Requirements Day 2013 in Zurich

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
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,521
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
64
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Specification-By-Example with Gherkin

  1. 1. FROM STAKEHOLDER EXAMPLES TO LIVING DOCUMENTATIONSpecification-By-Examplewith GherkinChristian Hassa - ch@techtalk.ch - Twitter: @chrishassaSwiss Requirements Day 2013, June 19th 2013
  2. 2. TechTalk Team
  3. 3. 5• Describe user needs or features• Unit of planning/prioritizationHelp to say “Not now” – instead of “No”• Future options for evolving the system• Reminder for a conversation• Deferring detail to thelast responsible momentWhat makes user stories agile?
  4. 4. 6RefiningUser Stories
  5. 5. 7Impact MappingStory MappingSpecification-By-ExampleEstablishing a shared understandingWhy?How?CodeEpicsDeliverables, OutputsImpacts, OutcomesEasier to define upfront Harder to define upfrontUser ActivitiesUser StoriesGoalsAcceptanceCriteriaBugreportsIsolated,formalizedexamplesExamplesReminderfor aconversation
  6. 6. 8Collecting Acceptance Criteria“I would try to put a book into theshopping cart …”“I would try to remove a bookfrom the shopping cart…”“I’d check whether the shopping cartis empty, when I enter the shop …”Books can be added toshopping cart.Books can be removed fromshopping cart.Shopping cart should be emptywhen entering the shop.... ? …As a potential customerI want to collect books in a shopping cartSo that I can order several books at once.“Imagine this story isalready implemented:how would you verify it?”“I would try to add 1000 books tothe shopping cart …”
  7. 7. 9Usingexamples
  8. 8. 11UI wire frames,existing UIrules, key examplesexisting artifacts,samplesDifferent models of examples
  9. 9. 12Discussing examples …public void TestInitialOrderDiscount(){Customer newCustomer = new Customer();Order newOrder = new Order(newCustomer);newOrder.AddBook(Catalog.Find(“ISBN-0955683610”));Assert.Equals(33.75,newOrder.Subtotal);}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 tobuy in our shop.Therefore we offer 10% discount for theirfirst order.Original idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com
  10. 10. 13Specification-by-ExampleExamples …• make abstract descriptionsbetter understandableHowever …• examples are usually not formallyexchanged or documentedBrian MarickExamples TestsRequirementsconsist ofdescribe verifyfulfillment of
  11. 11. 14Exploring a user need with examplesBooks in catalogue:Title AuthorSpecification-By-Example Gojko AdzicImpact Mapping Gojko AdzicExplore It! Elisabeth HendricksonCompetitive Engineering Tom Gilb… I want to find books in the catalogue by author and titleSearch for … Books found …Spec Specification-By-ExampleHend Explore It!et Explore It!, Competitive EngineeringContextActionAssertion
  12. 12. 15Key examples: Breaking the modelBooks in catalogue:Title AuthorSpecification-By-Example Gojko AdzicImpact Mapping Gojko AdzicExplore It! Elisabeth HendricksonCompetitive Engineering Tom Gilb… I want to find books in the catalogue by author and titleSearch for … Books found …Spec Specification-By-ExampleHend Explore It!et Explore It!, Competitive EngineeringWhat happens, if I search for“Explore Specification”?Can I search for singlecharacters, e.g. “e”?Is the number of search resultslimited, or paged?Is the search also performed in thesub-title of a book?
  13. 13. 16Discussion of acceptance criteriapublic void TestInitialOrderDiscount(){Customer newCustomer = new Customer();Order newOrder = new Order(newCustomer);newOrder.AddBook(Catalog.Find(“ISBN-0955683610”));Assert.Equals(33.75,newOrder.Subtotal);}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 tobuy in our shop.Therefore we offer 10% discount for theirfirst order.Original idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com
  14. 14. 17… illustrated with formalized examplesGiven the user has not ordered yetWhen the user adds a book with the price of EUR 37.5into the shopping cartThen the shopping cart sub-total is EUR 33.75.Original idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com
  15. 15. 18Discover hidden assumptionsActually, this is not quite right:Books on sale should be excluded.Original idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com
  16. 16. 19Collaboration: 3 amigos“HappyPath”TechnicalfeasabilityExceptions,border casesOriginal idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com
  17. 17. 20Abstract acceptance criteriaAs a shop visitorI want to collect books in my shopping basketso that I can purchase multiple books at once.Books can be added to the shopping basketBooks can be removed from the shopping basketShopping basket is initially emptyThe same book can be added multiple times to the shoppingbasket
  18. 18. 21Examples in GherkinAs a shop visitorI want to collect books in my shopping basketso that I can purchase multiple books at once.Books can be added to the shopping basketGiven my shopping basket is emptyWhen I add the book “Harry Potter” to my shopping basketThen my shopping basket should contain 1 copy of “Harry Potter”
  19. 19. 22As a shop visitorI want to collect books in my shopping basketso that I can purchase multiple books at once.Books can be added to the shopping basketExamples in GherkinGiven my shopping basket contains 1 copy of “Harry Potter”When I add the book “Harry Potter” to my shopping basketThen my shopping basket should contain 2 copies of “Harry Potter”The same book can be added multiple times to the shopping basket
  20. 20. 23The same book can be added multiple times to the shopping basketStructure of examplesGiven my shopping basket contains 1 copy of “Harry Potter”When I add the book “Harry Potter” to my shopping basketThen my shopping basket should contain 2 copies of “Harry Potter”Title: Describes intention/abstract acceptance criterionArrange: Context, initial state of the systemAct: Execution of the featureAssert: Assertion of observable behaviourAnd I should see the warning: “Book already existed in basket”Triple-Aconstraint“Checks”Chainingup steps
  21. 21. 24Life time ofexamples
  22. 22. 25Purpose of the examples• Shared understanding:acceptance criteria• Documentation:system details• Regression-tests:violated assumptions
  23. 23. 26Continuous validation with automationGiven my shopping basket contains 1 copy of “Harry Potter”When I add the book “Harry Potter” to my shopping basketThen my shopping basket should contain 2 copies of “Harry Potter”System„Step Definitions“ are binding individual stepsto an automatable interface of the application.AutomatableinterfaceUIAutomationAutomation does not necessarily have to bind to the UI.Automatability of system is supported/evolving with development.
  24. 24. 27Demohttp://www.specflow.orgGherkin automation for .NET• Visual Studio plugin (VS-Gallery)• NuGet Package
  25. 25. 32Livingdocumentation
  26. 26. 33Living documentationDrill into Details(Gherkin scenarios)Overview(Story Map)
  27. 27. 42Summary
  28. 28. 43Conclusions• Examples• Illustrate abstract requirements• Trigger new questions: collaborative discovery• Shared understanding• Living documentation• Automatically validated examples• Business readable regression tests• Reliable source of truth• Gherkin based automated examples• Open source, cross-platform• Requirement details versioned with source code• Similar tools: Fit/Fitnesse, Robot Framework, JBehave
  29. 29. 44Gherkin based automation toolswww.cukes.infowww.behat.orgRuby, Java, JavaScript, C++www.specflow.org.NET, Mono, Silverlight, WP7PHP
  30. 30. 45BooksGojko AdzicBridiging theCommunication GapGojko AdzicSpecification byExampleElisabeth HendricksonExplore IT!
  31. 31. 46
  32. 32. 47Christian Hassa: ch@techtalk.ch - @chrishassa

×