BDD, Gherkin, Cucumber and why we need it

  • View
    91

  • Download
    0

Embed Size (px)

Text of BDD, Gherkin, Cucumber and why we need it

  • BDD, Gherkin, Cucumber and why we need it

  • 7

    Impact Mapping

    Story Mapping

    Establishing a shared understandingWhy?

    How?Code

    Epics

    Deliverables, OutputsImpacts, Outcomes

    Easier to define upfront Harder to define upfront

    User Activities

    User Stories

    Goals

    AcceptanceCriteria

    Bugreports

    Isolated,formalizedexamples

    Examples

  • 8

    Collecting Acceptance Criteria

    I would try to put a book into the shopping cart

    Id check whether the shopping cart is empty, when I enter 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 is already implemented:

    how would you verify it?

    I would try to add 1000 books to the shopping cart

  • 8

    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

    Id 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 customerI want to collect books in a shopping cartSo 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

  • 9

    Usingexamples

  • 12

    Discussion of acceptance criteria

    {

    }

    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 Dinwiddiehttp://blog.gdinwiddie.com/

  • 12

    Discussion of acceptance criteria

    {

    }

    Register as bart_bookwormGo to /catalog/searchEnter ISBN-0955683610Click SearchClick Add to CartClick View CartVerify 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 Dinwiddiehttp://blog.gdinwiddie.com/

  • 16

    Discussion of acceptance criteria

    publicvoidTestInitialOrderDiscount(){

    Customer newCustomer= newCustomer();Order newOrder= newOrder(newCustomer);newOrder.AddBook(

    Catalog.Find(ISBN-0955683610));Assert.Equals(33.75,

    newOrder.Subtotal);}

    Register as bart_bookwormGo to /catalog/searchEnter ISBN-0955683610Click SearchClick Add to CartClick View CartVerify 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 Dinwiddiehttp://blog.gdinwiddie.com/

  • 13

    Specification by ExampleExamples make abstract descriptions

    better understandable

    However examples are usually not formally

    exchanged or documented

    Examples Tests

    Requirements

    consist of

    describe verifyfulfillment of

  • 16

    Discussionofacceptancecriteria

    publicvoidTestInitialOrderDiscount(){

    Customer newCustomer= newCustomer();Order newOrder= newOrder(newCustomer);newOrder.AddBook(

    Catalog.Find(ISBN-0955683610));Assert.Equals(33.75,

    newOrder.Subtotal);}

    Register as bart_bookwormGo to /catalog/searchEnter ISBN-0955683610Click SearchClick Add to CartClick View CartVerify 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 Dinwiddiehttp://blog.gdinwiddie.com/

  • 17

    with formalized examples

    Given When the user adds a book with the price of EUR 37.5 into the shopping cartThen the shopping cart sub-total is EUR 33.75.

    Original idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com

    the user has not ordered yet

  • 18

    Discover hidden assumptions

    Actually, this is not quite right:Books on sale should be excluded.

    Original idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com

  • 19

    Collaboration: 3 amigosHappyPath

    Technical feasability

    Exceptions, border cases

    Original idea for the illustration: George Dinwiddiehttp://blog.gdinwidiee.com

  • 20

    Abstract acceptance criteria

    Asa 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 basket

    Books can be removed from the shopping basket

    Shopping basket is initially emptyThe same book can be added multiple times to the shopping basket

  • 21

    Examples in Gherkin

    As 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 basket

    Given my shopping basket is empty

    When I add the book Harry Potter to my shopping basketThenmy shopping basket should contain 1 copy of Harry Potter

  • 22

    Asa shop visitorI want to collect books in my shopping basketso that I can purchase multiple books at once.

    Examples in Gherkin

    Given my shopping basket contains 1 copy of Harry Potter

    When I add the book Harry Potter to my shopping basketThenmy shopping basket should contain 2 copies of Harry Potter

    The same book can be added multiple times to the shopping basket

  • 23

    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 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 behaviour

    And I should see the warning: Book already existed in basket

    Triple-AconstraintChecks

    Chainingup steps

  • 25

    Purpose of the examples Shared understanding of

    acceptance criteria

    Documentation:system details

    Regression-tests:violated assumptions

  • 26

    Continuous validation with automation

    Given 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.

    Automatableinterface

    UIAutomation

    Automation does not necessarily have to bind to the UI.

    Automatability of system is supported/evolving with development.

  • 24

    Automation examples

  • 24

    NO

  • https://github.com/radiant/radiant/tree/master/features/https://github.com/carrierwaveuploader/carrierwave/tree/master/featureshttps://github.com/webjam/webjam/tree/master/features

    Better look at real projects

    https://github.com/radiant/radiant/tree/master/features/https://github.com/carrierwaveuploader/carrierwave/tree/master/features

  • 43

    Conclusions 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

  • 44

    Gherkin based automationtools

    www.cukes.info

    www.behat.org

    Ruby, Java, JavaScript, C++

    www.specflow.org.NET, Mono, Silverlight, WP7

    PHP

  • 45

    Books

    Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25