Tutorial: Implementing Specification-By-Example with Gherkin
Upcoming SlideShare
Loading in...5
×
 

Tutorial: Implementing Specification-By-Example with Gherkin

on

  • 3,660 views

1/2 day Tutorial held at XP 2013 conference in Vienna ...

1/2 day Tutorial held at XP 2013 conference in Vienna

Many teams struggle with the implementation of user story acceptance criteria and having a shared understanding about the expected story outcomes. This often results in missed stakeholder expectations, ad-hoc assumptions made by the team during implementation and conflict between team members and the product owner around testing.

In this tutorial, you will learn how specification-by-example and acceptance test driven development will address team conflict, missed stakeholder expectations and overall increasing the level of clarity on the project end-to-end. The presentation will cover the theory behind ATDD, case-studies and practical experience from real projects and several hands-on exercises to try out the presented concepts.

You will leave this tutorial 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.

Statistics

Views

Total Views
3,660
Views on SlideShare
3,652
Embed Views
8

Actions

Likes
3
Downloads
100
Comments
0

1 Embed 8

https://twitter.com 8

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Tutorial: Implementing Specification-By-Example with Gherkin Tutorial: Implementing Specification-By-Example with Gherkin Presentation Transcript

    • CHRISTIAN HASSA (CH@TECHTALK.AT)TWITTER: @CHRISHASSAXP 2013 Vienna, June 3rd 2013Specification-By-Examplewith Gherkin
    • About me• Managing Partner at TechTalk• Working as/coaching Product OwnersTechTalk office Vienna/Austria
    • • Agile consulting and delivery• Offices: Vienna, Budapest, ZurichTechTalk TeamAbout my Team
    • 4RefiningUser Stories
    • 5Impact MappingStory MappingSpecification-By-ExampleEstablishing a shared understandingWhy?How?CodeAcceptanceCriterionEpicCapabilityImpact, GoalEasier to define upfront Harder to define upfrontBugreportIsolated,formalizedexampleFeatureUser StoryExampleReminderfor adiscussion
    • 6Collecting 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 …”“I would try to add the same bookagain to the shopping cart …”Books can be placed intoshopping cart.Books can be removed fromshopping cart.Shopping cart should be emptywhen entering the shop.Adding same book again toshopping cart should increasequantity.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?”
    • 7Example:Mobile Ticket for Wiener Linien
    • 8Exercise: Smart Alarm• What would you try out when the following user story wasdone?• Collect and write down the list of discussed acceptance criteria• Work in groups of 2-3As a regular travelerI want to setup asmart alarmso that I can bewarned about servicedisruptionsI want to setupmultiple smartalarmsso that I can planahead for differenttravel plans I have
    • 9Usingexamples
    • 10UI wire frames,existing UIrules, key examplesexisting artifacts,samplesExamples for user stories
    • 11Specification-by-ExampleExamples …• make abstract descriptionsbetter understandableHowever …• examples are usually not formallyexchanged or documentedBrian MarickExamples TestsRequirementsconsist ofdescribe verifyfulfillment of
    • 12Discussion 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
    • 13… 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
    • 14Discover hidden assumptionsActually, this is not quite right:Books on sale should be excluded.Original idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com
    • 15Collaboration: 3 amigos“HappyPath”TechnicalfeasabilityExceptions,border casesOriginal idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com
    • 16Abstract 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
    • 17Examples for 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 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”
    • 18As 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 for acceptance criteriaGiven 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
    • 19The 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
    • 20Gherkin
    • 21Feature: Description of feature or user storySzenariogrundriss: Beschreibung des AkzeptanzkriteriumsSzenario: Beschreibung des AkzeptanzkriteriumsGherkin Feature FilesBackground: context for all scenarios in the feature fileScenario: Description of acceptance criterionAngenommen/Wenn/Dann: Automatisierte Szenario SchritteGiven/When/Then: automated scenario stepsScenario Outline: Description of acceptance criterionAngenommen/Wenn/Dann: Automatisierte Szenario SchritteGiven/When/Then: automated scenario steps with <place holder>Examples: table with examples for <place holders>Examples: table with examples for <place holders>Given: automated scenario steps@tagname@tagname@tagname@tagname
    • 22FeatureFeature: Description of feature or user story#language:en-en@doneFeature: Shopping cartAs visitor of the web shopI want to collect books in a shopping cartso that I can- prepare a short list of books I want to order- combine multiple books in one shipment@Tagname
    • 23ScenarioScenario: Description of acceptance criterionAngenommen/Wenn/Dann: Automatisierte Szenario SchritteGiven/When/Then: automated scenario steps@Tagname@inprogressScenario: The same book can be added multiple times to shopping cartGiven my shopping cart contains 1 copy of "Harry Potter"When I add the book "Harry Potter" to the shopping cartThen my shopping cart contains 2 copies of "Harry Potter"And a warning is displayed: "You have added the same book again"
    • 24Scenario OutlineScenario Outline: Description of acceptance criterionAngenommen/Wenn/Dann: Automatisierte Szenario SchritteExamples: table with examples for <place holders>Given/When/Then: automated scenario steps with <place holder>Examples: table with examples for <place holders>@Tagname@TagnameScenario Outline: Simple searchWhen I search for books by the phrase <search phrase>Then the list of found books should contain only: <books>Examples:| search phrase | books | Explanation || Domain | Domain … | whole words are matched || Analysis Communication | Bridging…, Analysis … | multiple words are matched with OR |Scenario Outline: Candidate profile can only be saved with <mandatory field>When I enter a valid candidate profile, without filling in <mandatory field>Then I see the following validation error: field <mandatory field> missingExamples: Main fields| mandatory field || email || name || first name |Examples: Extended fields| mandatory field || birthdate |
    • 25BackgroundBackground: context for all scenarios in the feature fileGiven: automated scenario stepsBackground:Given the catalog contains the following books| Title | Author || Specification-By-Example | Gojko Adzic || Agile Testing | Lisa Crispin, Janet Gregory || Scrum Field Guide | Mitch Lacey |
    • 26Scenario step argumentsGiven the catalog contains the following books| Title | Author || Specification-By-Example | Gojko Adzic || Agile Testing | Lisa Crispin, Janet Gregory || Scrum Field Guide | Mitch Lacey |When I add the book "Harry Potter" to the shopping cartScalar arguments:Table arguments:
    • 27Exercise• Work in same previous groups of 2-3• Pick an acceptance criteria from thepreviously compiled list• Outline usage examples with the followingstructure• Given: Context, initial state• When: utilization of the feature• Then: assertions of observable behaviour• Validate that scenario title (acceptancecriterion) still describes intention offormalized scenario
    • 28Life time ofexamples
    • 29Purpose of the examples• Shared understanding:acceptance criteria• Documentation:system details• Regression-tests:violated assumptions
    • 30Continuous 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.
    • 31Demohttp://www.specflow.orgGherkin automation for .NET• Visual Studio plugin (VS-Gallery)• NuGet Package
    • 32Some more complex exercisesChoose between• Best-fare option ticket• Smart Alarm
    • 33Best-fare option ticket• Assumptions• Ticket price is always adjusted duringvalidation to the best option (consideringall previous trips)• Feedback about cost of travel and ticketoption (type) after each validation• Valid in the core zone 100• Scope of the story• Different travel scenarios and how theprice adjusts• Billings resulting from the user’s travel• Feedback to traveler (cost of travel, statusof ticket) when validating ticket• Out of scope for this story• Credit limit of traveler• Authentication of ticket (validity)As an ad-hoc travelerI want my ticket to adjustto the best available farewhenever I validateSo that I don’t need tostudy upfront which ticketI needTicket Type PriceSingle trip 2,1024 hours 7,1048 hours 12,4072 hours 15,408 days 35,80Week 15,00Month 45,00Year 365,00
    • 34Smart Alarm• Assumptions• User can specify route to monitor fordisruptions• User can specify when disruptionsshould trigger the alarm earlier(minutes before alarm)• Scope of the story• Different possibilities of disruptionsprovided by GTFS and their impact onactivating the alarm• Out of scope for this story• Configuring routes (the user isselecting an already defined route)• Setting up alarms (the user hasalready setup an alarm)As a regular travelerI want to have a smartalarm that activatesearlier when there aretraffic disruptions on myrouteSo that I can travel earlierto be still on time for myappointment
    • 35ExerciseChoose between• Best-fare option ticket• Smart AlarmCollect and discuss scenarios• What would you try out?• Collect examples• Limit scope of the story
    • 36ExerciseRefine scenarios and formalizeinto Gherkin• Start with a “warm-up” scenario• Increase complexity with additionalscenarios• Reconsider structure of scenarios as yourefine them• Validate scenario title/description afterrefinement
    • 37Impact ontesting
    • 38Test automation becomes expensivewhen …• trying to automatemanual tests• making testsunreadable whenautomating them• automating aftercompletingdevelopmentstructurereadabilitypoint in time
    • 39StructureManual testsAsserts Multiple combinedfeaturesStructure ACT-ASSERT-ACT-ASSERT-ACT-ASSERT-…Dependent featuresLong test path withhigh chance to breakCause and impact oferror hard to traceAutomated CheckSingle aspect of asingle featureARRANGE –ACT –ASSERTIndependent featuresShort test path withlower chance to breakCause and impact oferror easy to relate
    • 40Test automation pyramidUserjourneysAcceptance-criteriaUnitsexploratorytestingSource: Mike CohnmanyfewhardeasyAutomatability
    • 41// Go to web page http://localhost:40001/ using new browser instanceBrowserWindow localhostBrowser = BrowserWindow.Launch(new System.Uri(this.RecordedMethod1Params.Url));// Click Register found item linkMouse.Click(uIFundstückerfassenHyperlink, new Point(56, 9));// Click Save buttonMouse.Click(uISpeichernButton, new Point(44, 14));int fundNr1 = int.Parse(uIFundNr127Pane.InnerText.Substring(9));// Click Register found item linkMouse.Click(uIFundstückerfassenHyperlink, new Point(63, 7));// Click Save buttonMouse.Click(uISpeichernButton, new Point(34, 11));int fundNr2 = int.Parse(uIFundNr128Pane.InnerText.Substring(9));Assert.IsTrue(fundNr1 + 1 == fundNr2);// Click Close buttonMouse.Click(uICloseButton, new Point(26, 11));Readability
    • 42A readable test caseScenario: New found items should receive aconsecutive number for the current yearGiven the previous found item of thecurrent year had the number 145When I register a new found itemThen the last found item of thecurrent year should have the number 146
    • 43When to test (point in time)Acceptance criteria(ATDD, BDD)Unit Tests(TDD)business viewtechnical viewExploratory testsWorkflow testsPerformance, Scalability,Usability,Security, …definingtheproductcriticizingtheproductNew dimension: defining the productSynergy: Specification of requirements and testsAgile Testing Quadrants: Brian Marick
    • 44Manual Testing is always necessary!UserjourneysAcceptance-criteriaUnitsexploratorytestingSource: Mike CohnmanyfewhardereasierAutomatabilityManualCheckafterStoryDoneMainsuccesspathesUndiscoveredacceptancecriteriaNo/(few)manualregressionchecksFew pathesare enoughMore timefor exploration
    • 47Impact ondevelopment
    • 48Workflow - TDD
    • 49Extending TDD for business
    • 50Transparency for stakeholdersIn Progress
    • 51Current sprint report: all sprint scenarios
    • 52Starting with first scenario (AC)
    • 53Finishing the first scenario (AC)
    • 54Progressing scenario after scenario
    • 55Progressing scenario after scenario
    • 56Progressing scenario after scenario
    • 57Implementing user stories in parallel
    • 58First user story ready for testing
    • 59Manual testing can start even earlier
    • 60Work done already can break again
    • 61Work done already can break again
    • 62See what is temporarily not working
    • 64Livingdocumentation
    • 65Living documentationDrill into Details(Gherkin scenarios)Overview(Story Map)
    • 66User Stories vs. FeaturesProduct/Sprint BacklogUser Story 1AccCrit 1AccCrit 2User Story 2AccCrit 3AccCrit 4Living DocumentationFeature 1AccCrit 1AccCrit 2Feature nAccCrit 4AccCrit mUser Story nAccCrit 5AccCrit mAccCrit 3AccCrit 5„Done“• Future options of the system• Organized/refined according topriority, value, effort, risk, ...• Next possible increments ofthe product (units of work)• Current state of the system• Organized/refined forfunctional overview• Versioned and maintainedtogether with source code
    • 67Lessonslearned
    • 68Collaboration over specificationDocumentation after conversation• Collaborative discovery• Should trigger new questions• Infinite number of examples• Readability and ability to automate
    • 69Collaboration smells• Silos and too formal hand-overs• Formalization cannot follow implementation• Scenarios replace communication• Scenarios inhibit consideration of solutions• Scenarios inhibit discovery of new things• Duty after development is done• Unreadable scenarios without value• High cost for creation and maintenance• Technical problems with automation
    • 70Level of automationControllerBusiness LayerData LayerModelViewBrowserautomationTrigger behaviourthrough controllerAssert behaviouron model, db, ..Setup pre-conditionsthrough serviceinterfacesOut-of-processIn-process
    • 71Test execution performance• Grouping tests• Current WIP• Completed work• Database• In-memory• Templates for setup• Parallel execution• Smart execution order
    • 72Internal vs. external DSLExample Source:Liz Keoghhttps://github.com/lunivore/tictactoe-java/blob/master/scenarios/com/lunivore/tictactoe/scenarios/Three_in_a_row_wins.java
    • 73Non-functional acceptance criteriaGiven there are 100,000 users registered on the systemWhen I create a new accountThen I should be taken to my dashboard within 5msGiven 1000 users are hitting the homepagesimultaneouslyThen each user should get a response within 2msMatt Wynnehttp://blog.mattwynne.net/2012/03/13/using-cucumber-for-load-testing
    • 74Tools
    • 75Gherkin automation toolswww.cukes.infowww.behat.orgRuby, Java, JavaScript, C++www.specflow.org.NET, Mono, Silverlight, WP7PHP
    • 76
    • 77BooksGojko AdzicBridiging theCommunication GapGojko AdzicSpecification byExampleElisabeth HendricksonExplore IT!
    • 78Christian Hassa: ch@techtalk.at - @chrishassa