Specification-By-Example with Gherkin

61
FROM STAKEHOLDER EXAMPLES TO LIVING DOCUMENTATION Specification-By-Example with Gherkin Christian Hassa - [email protected] - Twitter: @chrishassa GoTo Night Zurich, June 12th 2014

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

Page 1: Specification-By-Example with Gherkin

FROM STAKEHOLDER EXAMPLES TO LIVING DOCUMENTATION

Specification-By-Example with Gherkin

Christian Hassa - [email protected] - Twitter: @chrishassaGoTo Night Zurich, June 12th 2014

Page 2: Specification-By-Example with Gherkin

2

2000 2009

2010

2007

Scrum

1997

1992 2014

Page 3: Specification-By-Example with Gherkin

7

User Story life-cycleIdea

Need

Problem

Page 4: Specification-By-Example with Gherkin

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

Page 5: Specification-By-Example with Gherkin

9

EvolvingUser Stories

intoSpecifications

Page 6: Specification-By-Example with Gherkin

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

Page 7: Specification-By-Example with Gherkin

11

Why?Outcomes

SpecificationsHow?

Epics

Deliverables

Impacts

earlier later

User Activities

User Stories

Goals

Specifying user stories

Code

Reminderfor aconversation

Page 8: Specification-By-Example with Gherkin

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

Page 9: Specification-By-Example with Gherkin

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

Page 10: Specification-By-Example with Gherkin

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

Page 11: Specification-By-Example with Gherkin

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

Page 12: Specification-By-Example with Gherkin

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.

Page 13: Specification-By-Example with Gherkin

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

Page 14: Specification-By-Example with Gherkin

18

Collaboration: 3 amigos

“HappyPath”

Technical feasability

Exceptions, border cases

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

Page 15: Specification-By-Example with Gherkin

19

Structuringthe conversation

Page 16: Specification-By-Example with Gherkin

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

Page 17: Specification-By-Example with Gherkin

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

Page 18: Specification-By-Example with Gherkin

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?

Page 19: Specification-By-Example with Gherkin

23

UI wire frames,existing UI

rules, key examples

existing artifacts,samples

Different kinds of examples

Page 20: Specification-By-Example with Gherkin

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

Page 21: Specification-By-Example with Gherkin

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”

Page 22: Specification-By-Example with Gherkin

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

Page 23: Specification-By-Example with Gherkin

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

Page 24: Specification-By-Example with Gherkin

28

Purpose of the examples

• Shared understanding:acceptance criteria

•Documentation:system details

• Regression-tests:violated specifications

Page 25: Specification-By-Example with Gherkin

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.

Page 26: Specification-By-Example with Gherkin

30

Demo

http://www.specflow.org

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

Page 27: Specification-By-Example with Gherkin

32

Booking system

Page 28: Specification-By-Example with Gherkin

33

Payroll calculation

Page 29: Specification-By-Example with Gherkin

34

eVoting system

Page 30: Specification-By-Example with Gherkin

35

Examples in Excel

Page 31: Specification-By-Example with Gherkin

36

Business readableteam flowwith ATDD

Page 32: Specification-By-Example with Gherkin

37

Tasks are not business readable

Create bookings for a fixed time loop on

Page 33: Specification-By-Example with Gherkin

38

… but scenarios (AC) are

Page 34: Specification-By-Example with Gherkin

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

Page 35: Specification-By-Example with Gherkin

40

Business readable progress

In Progress

Page 36: Specification-By-Example with Gherkin

41

Current sprint report: all sprint scenarios

Page 37: Specification-By-Example with Gherkin

42

Starting with first scenario (AC)

Page 38: Specification-By-Example with Gherkin

43

Finishing the first scenario (AC)

Page 39: Specification-By-Example with Gherkin

44

Progressing scenario after scenario

Page 40: Specification-By-Example with Gherkin

45

Progressing scenario after scenario

Page 41: Specification-By-Example with Gherkin

46

Progressing scenario after scenario

Page 42: Specification-By-Example with Gherkin

47

Implementing user stories in parallel

Page 43: Specification-By-Example with Gherkin

48

First user story ready for testing

Page 44: Specification-By-Example with Gherkin

49

Testing can start even earlier

Page 45: Specification-By-Example with Gherkin

50

Already done work can break again

Page 46: Specification-By-Example with Gherkin

51

Already done work can break again

Page 47: Specification-By-Example with Gherkin

52

See what is temporarily not working

Page 48: Specification-By-Example with Gherkin

53

Livingdocumentation

Page 49: Specification-By-Example with Gherkin

54

Living documentation

Drill into Details(Gherkin scenarios)

Overview(Story Map)

Page 50: Specification-By-Example with Gherkin

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

Page 51: Specification-By-Example with Gherkin

56

Gettingstarted with

Specification-By-Example

Page 52: Specification-By-Example with Gherkin

57

Start with the conversation

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

Page 53: Specification-By-Example with Gherkin

58

Grow your team’s skills

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

Page 54: Specification-By-Example with Gherkin

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

Page 55: Specification-By-Example with Gherkin

60

Treat test automationas a first class citizen

• Emerging architecture• Refactoring•Definition of Done

Page 56: Specification-By-Example with Gherkin

61

Books to read

Gojko AdzicBridiging theCommunication Gap

Gojko AdzicSpecification byExample

Elisabeth HendricksonExplore IT!

Page 57: Specification-By-Example with Gherkin

Coaching

Page 58: Specification-By-Example with Gherkin

Coaching

Page 59: Specification-By-Example with Gherkin

65

Page 60: Specification-By-Example with Gherkin
Page 61: Specification-By-Example with Gherkin

69 Christian Hassa: [email protected] - @chrishassa