Specification-By-Example with Gherkin

Post on 10-May-2015

1.177 views 2 download

Tags:

description

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.

Transcript of Specification-By-Example with Gherkin

FROM STAKEHOLDER EXAMPLES TO LIVING DOCUMENTATION

Specification-By-Example with Gherkin

Christian Hassa - ch@techtalk.ch - Twitter: @chrishassaGoTo Night Zurich, June 12th 2014

2

2000 2009

2010

2007

Scrum

1997

1992 2014

7

User Story life-cycleIdea

Need

Problem

8

Impact Mapping

Story Mapping

Specification-By-Example

Why?Outcomes

SpecificationsHow?

AcceptanceCriteria

Epics

Deliverables

Impacts

earlier later

User Activities

User Stories

Examples

Goals

Agile Product Ownership

Code

9

EvolvingUser Stories

intoSpecifications

10

Impact Mapping

Story Mapping

Specification-By-Example

Why?Outcomes

SpecificationsHow?

AcceptanceCriteria

Epics

Deliverables

Impacts

earlier later

User Activities

User Stories

Examples

Goals

Specifying user stories

Code

11

Why?Outcomes

SpecificationsHow?

Epics

Deliverables

Impacts

earlier later

User Activities

User Stories

Goals

Specifying user stories

Code

Reminderfor aconversation

12

Having a conversation …

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 to buy in our shop.Therefore we offer 10% discount for their first order.

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

13

Specification-By-Example

Why?Outcomes

SpecificationsHow?

AcceptanceCriteria

Epics

Deliverables

Impacts

earlier later

User Activities

User Stories

Examples

Goals

Establishing a shared understanding

Code

Bugreports

Isolated,formalizedexamples

14

Specification-by-ExampleExamples …• make abstract descriptions

better understandable

However …• examples are usually not formally

exchanged or documented

Brian Marick

Examples Tests

Requirements

consist of

describe verifyfulfillment of

15

Discussing acceptance criteria …

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 to buy in our shop.Therefore we offer 10% discount for their first order.

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

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

We would like to encourage new users to buy in our shop.Therefore we offer 10% discount for their first order.

17

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

18

Collaboration: 3 amigos

“HappyPath”

Technical feasability

Exceptions, border cases

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

19

Structuringthe conversation

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 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 …”

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

ActionAssertion

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?

23

UI wire frames,existing UI

rules, key examples

existing artifacts,samples

Different kinds of examples

24

Abstract acceptance criteria

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

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

25

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 basket

Then my shopping basket should contain 1 copy of “Harry Potter”

26

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

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

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-Aconstraint“Checks”

Chainingup steps

28

Purpose of the examples

• Shared understanding:acceptance criteria

•Documentation:system details

• Regression-tests:violated specifications

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

30

Demo

http://www.specflow.org

Gherkin automation for .NET• Visual Studio plugin (VS-Gallery)•NuGet Package

32

Booking system

33

Payroll calculation

34

eVoting system

35

Examples in Excel

36

Business readableteam flowwith ATDD

37

Tasks are not business readable

Create bookings for a fixed time loop on

38

… but scenarios (AC) are

39

ATDD cycle

Write afailing

unit test

Make thetest pass

Refactor

Write a failingacceptance

test

Deploy andmeasureimpact

Refine feature, if needed(new user story)

break downunits

extendsystemUser Story

AC/Scenario 1

AC/Scenario 2

AC/Scenario …

AC/Scenario n

modifysystem

Expectedimpact

40

Business readable progress

In Progress

41

Current sprint report: all sprint scenarios

42

Starting with first scenario (AC)

43

Finishing the first scenario (AC)

44

Progressing scenario after scenario

45

Progressing scenario after scenario

46

Progressing scenario after scenario

47

Implementing user stories in parallel

48

First user story ready for testing

49

Testing can start even earlier

50

Already done work can break again

51

Already done work can break again

52

See what is temporarily not working

53

Livingdocumentation

54

Living documentation

Drill into Details(Gherkin scenarios)

Overview(Story Map)

55

User Stories vs. Features

Product/Sprint Backlog

User Story 1AccCrit 1

AccCrit 2

User Story 2AccCrit 3

AccCrit 4

Living Documentation

Feature 1

AccCrit 1

AccCrit 2

Feature nAccCrit 4

AccCrit mUser Story n

AccCrit 5

AccCrit m

AccCrit 3AccCrit 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

56

Gettingstarted with

Specification-By-Example

57

Start with the conversation

• What happens when … ?• What would you try out … ?• Discuss based on concrete examples

58

Grow your team’s skills

• (Acceptance) Test Driven Development• Test Automation Pyramid• Exploratory Testing

59

Decide for an automation toolGherkin tools available for Ruby, Java, .NET, JavaScript, PHP, …

www.specflow.org

www.cukes.info

Other ATDD tools like:JBehave, Fitnesse, Robotframework,Concordion, …

60

Treat test automationas a first class citizen

• Emerging architecture• Refactoring•Definition of Done

61

Books to read

Gojko AdzicBridiging theCommunication Gap

Gojko AdzicSpecification byExample

Elisabeth HendricksonExplore IT!

Coaching

Coaching

65

69 Christian Hassa: ch@techtalk.ch - @chrishassa