specification-by-example with gherkin

77
Specification-By-Example with Gherkin Christian Hassa, TechTalk ([email protected], @chr99ha)

Upload: chassa

Post on 12-May-2015

9.920 views

Category:

Documents


1 download

DESCRIPTION

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. This session shows 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 and case-studies and practical experience from real projects. The talk was held at the ALM summit 3 in Redmond, January 2013. Recording of the talk can be found here: http://channel9.msdn.com/Events/ALM-Summit/ALM-Summit-3/Implementing-ATDD-and-Specification-By-Example

TRANSCRIPT

Page 1: Specification-By-Example with Gherkin

Specification-By-Example with Gherkin

Christian Hassa, TechTalk ([email protected], @chr99ha)

Page 2: Specification-By-Example with Gherkin

Almost 4 years later …

#106 in Visual Studio Gallery (30.1.2013)

#135 in NuGet (30.1.2013)

~800 visits daily

~ 4000 active users > 30 contributors

Page 3: Specification-By-Example with Gherkin

Goals

Make you curious about Specification-By-Example

New perspective for SpecFlow users

Page 4: Specification-By-Example with Gherkin

About me • Managing Partner at TechTalk • Agile consulting and delivery • Based in Europe:

Vienna, Budapest, Zurich

Page 5: Specification-By-Example with Gherkin

Terminology

• Specification-By-Example

• Acceptance Test Driven Development (ATDD)

• Behaviour Driven Development (BDD)

Page 6: Specification-By-Example with Gherkin

Agile requirements

Page 7: Specification-By-Example with Gherkin

Purpose of user stories?

• Describe user needs

• Unit of prioritization

• Unit of planning

• Reminder for a discussion

• Mechanism to defer detail

Page 8: Specification-By-Example with Gherkin

Requirement levels Impact Mapping

Story Mapping

Specification-By-Example

Why?

How?

Acceptance Criterion

Epic

Deliverable, Outcome

Impact, Goal

Easier to define upfront Harder to define upfront

Reminder for a discussion

Bug report

Isolated, formalized example

User Activity

User Story

Example

Code

Page 9: Specification-By-Example with Gherkin

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

“I would try to add the same book again to the shopping cart …”

Books can be placed into shopping cart.

Books can be removed from shopping cart.

Shopping cart should be empty when entering the shop.

Adding same book again to shopping cart should increase quantity.

As a potential customer I want to collect books in a shopping cart So that I can order several books at once.

“Imagine this story is already implemented: What would you try out?”

Page 10: Specification-By-Example with Gherkin

Using examples

Page 11: Specification-By-Example with Gherkin

Examples for user stories

UI wire frames, existing UI

rules, key examples

existing artifacts, mock-ups

Page 12: Specification-By-Example with Gherkin

Discussion of acceptance criteria

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

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.

Page 13: Specification-By-Example with Gherkin

Specification-By-Example Examples …

– make abstract descriptions better understandable

– are usually not formally exchanged or documented

Brian Marick

Examples Tests

Requirements

consist of

describe verify fulfillment of

Page 14: Specification-By-Example with Gherkin

Discussion of acceptance criteria

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

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.

Page 15: Specification-By-Example with Gherkin

Illustrated with shared examples

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

Given the user has not ordered yet When the user adds a book with the price of USD 37.50 into the shopping cart Then the shopping cart sub-total should be USD 33.75.

Page 16: Specification-By-Example with Gherkin

Discover new aspects

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

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

Page 17: Specification-By-Example with Gherkin

Collaboration: 3 amigos “Happy Path”

Technical feasability

Exceptions, border cases

Page 18: Specification-By-Example with Gherkin

Abstract acceptance criteria As a shop visitor I want to collect books in my shopping basket so 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 19: Specification-By-Example with Gherkin

Formalizing examples As a shop visitor I want to collect books in my shopping basket so 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 20: Specification-By-Example with Gherkin

Formalizing examples As a shop visitor I want to collect books in my shopping basket so that I can purchase multiple books at once.

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

When I add the book “Harry Potter” to my shopping basket

Then my shopping basket should contain 2 copies of “Harry Potter”

Given my shopping basket contains 1 copy of “Harry Potter”

Page 21: Specification-By-Example with Gherkin

Example structure

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

When I add the book “Harry Potter” to my shopping basket

Then my shopping basket should contain 2 copies of “Harry Potter”

Given my shopping basket contains 1 copy of “Harry Potter”

Title: Describes isolated, focused intention=abstract acceptance criterion

Arrange: Context, initial state of the system

Act: Execution of the feature Assert: Assertion of observable behavior

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

Triple-A constraint “Checks”

Steps can be chained up

Evolution of a domain specific test and specification language.

Page 22: Specification-By-Example with Gherkin

Life time of examples

Page 23: Specification-By-Example with Gherkin

Purpose of examples

• Shared understanding: acceptance criteria

• Documentation: system details

• Regression-tests: violated assumptions

Page 24: Specification-By-Example with Gherkin

Continuous validation

When I add the book “Harry Potter” to my shopping basket

Then my shopping basket should contain 2 copies of “Harry Potter”

Given my shopping basket contains 1 copy of “Harry Potter”

„Step Definitions“ are binding individual steps to an automatable interface of the application.

Automation does not necessarily have to bind to the UI.

Automation of system is supported/evolving with development.

System UI Automation

Page 25: Specification-By-Example with Gherkin

Demo

Gherkin automation for .NET

• Visual Studio plugin (VS-Gallery)

• NuGet Package

http://www.specflow.org

Page 26: Specification-By-Example with Gherkin

Impact on testing

Page 27: Specification-By-Example with Gherkin

Test automation becomes expensive, when …

• trying to automate manual tests

• making tests unreadable when automating them

• automating only after completing implementation

structure

readability

when to test

Page 28: Specification-By-Example with Gherkin

Structure Manual tests

Asserts Multiple combined features

Structure ACT-ASSERT- ACT-ASSERT- ACT-ASSERT- …

Dependent on existence of other features Long test path with high chance to break Cause and impact of an error hard to trace.

Automated Check

Single aspect of a single feature

ARRANGE – ACT – ASSERT

Independent of other features Short test path with lower chance to break Cause and impact of an error easier to trace.

Page 29: Specification-By-Example with Gherkin

Test automation pyramid

User journeys

Acceptance-criteria

Units many

harder

easier

Au

tom

ati

on

few

exploratory testing

Source: Mike Cohn

Page 30: Specification-By-Example with Gherkin

Readability // Go to web page 'http://localhost:40001/' using new browser instance BrowserWindow localhostBrowser = BrowserWindow.Launch( new System.Uri(this.RecordedMethod1Params.Url)); // Click 'Register found item' link Mouse.Click(uIRegisterFoundItemHyperlink, new Point(56, 9)); // Click 'Save' button Mouse.Click(uISaveButton, new Point(44, 14)); int foundItemNo1 = int.Parse(uIFundNr127Pane.InnerText.Substring(9)); // Click 'Register found item' link Mouse.Click(uIRegisterFoundItemHyperlink, new Point(63, 7)); // Click 'Save' button Mouse.Click(uISaveButton, new Point(34, 11)); int foundItemNo2 = int.Parse(uIFundNr128Pane.InnerText.Substring(9)); Assert.IsTrue(foundItemNo1 + 1 == foundItemNo2); // Click 'Close' button Mouse.Click(uICloseButton, new Point(26, 11));

Page 31: Specification-By-Example with Gherkin

A readable test case Scenario: New found items should receive a consecutive number for the current year Given the previous found item of the current year had the number 145 When I register a new found item Then the last found item of the current year should have the number 146

Page 32: Specification-By-Example with Gherkin

When to test

Acceptance criteria (ATDD, BDD)

Unit Tests (TDD)

business view

technical view

Exploratory tests Workflow tests

Performance, Scalability, Usability,Security, …

de

fin

ing

th

e p

rod

uct

criticizing

the

pro

du

ct

New dimension: defining the product Synergy: Specification of requirements and tests

Agile Testing Quadrants: Brian Marick

Page 33: Specification-By-Example with Gherkin

Manual testing is still necessary!

User journeys

Acceptance-criteria

Units

exploratory testing

Manual Check after story done

Main success paths

Undiscovered acceptance criteria

No/(few) manual regression checks

Few paths are enough

More time for exploration

Page 34: Specification-By-Example with Gherkin

Cross-functional work

Sprint 1 Sprint 2 Sprint 3

short iteration

US4 Plan

Implement & autom. test

US5 Plan

Implement & autom. test

US2 Plan

Implement & autom. test

US3

Plan

Implement & autom. test

US6 Plan

Implement & autom. test

US1 Plan

Implement & autom. test

US7 Plan

Implement & autom. test

US8 Plan

Implement & autom. test

US9 Plan

Implement & autom. test

Explo

ratory Tests

Specification and test

Collaboration for defining acceptance criteria

Collaboration for automation

Preventing bugs instead of finding them!

Extension of “Test Cases”

Limit WIP

Collaboration in manual

testing

Page 35: Specification-By-Example with Gherkin

Impact on development

Page 36: Specification-By-Example with Gherkin

TDD workflow

Page 37: Specification-By-Example with Gherkin

Extending TDD for business

Page 38: Specification-By-Example with Gherkin

Transparency for stakeholders

In Progress

Page 39: Specification-By-Example with Gherkin

Current sprint report: all scenarios

Page 40: Specification-By-Example with Gherkin

Starting with first scenario

Page 41: Specification-By-Example with Gherkin

Finishing first scenario

Page 42: Specification-By-Example with Gherkin

Progressing on scenarios

Page 43: Specification-By-Example with Gherkin

Progressing on scenarios

Page 44: Specification-By-Example with Gherkin

Progressing on scenarios

Page 45: Specification-By-Example with Gherkin

Progressing on scenarios

Page 46: Specification-By-Example with Gherkin

First user story ready for testing

Page 47: Specification-By-Example with Gherkin

Earlier start of manual testing

Page 48: Specification-By-Example with Gherkin

Done work can break again

Page 49: Specification-By-Example with Gherkin

Done work can break again

Page 50: Specification-By-Example with Gherkin

Business readable error reports

Page 51: Specification-By-Example with Gherkin

Living documentation

Page 52: Specification-By-Example with Gherkin

Higher level scenario structure

Story Mapping

Why?

How?

Acceptance Criterion

Epic

Deliverable, Outcome

Impact, Goal

User Activity

User Story

Example

Code Easier to define upfront Harder to define upfront

Page 53: Specification-By-Example with Gherkin

Story Maps

• Original concept by Jeff Patton

• Support iterative product design

• Optimized for desired outcome or deliverable the system should support

Page 54: Specification-By-Example with Gherkin

Building story maps Get popular books delivered fast and

conveniently

Find book

Collect books

Order Wait for delivery

Receive delivery

time

browse best

sellers

shopping basket

enter address

delivery slip

delivery notification

pay with credit card

search book by

title wish list

inquiry order status

desired outcome or deliverable

user activities

system features

nec

essi

ty

Page 55: Specification-By-Example with Gherkin

Walking skeleton

Enabling build–measure-learn Get popular books delivered fast and

conveniently

Find book

Collect books

Order Wait for delivery

Receive delivery

time

browse best

sellers

enter address

delivery slip

pay with credit card

search book by

title wish list

inquiry order status

nec

essi

ty

shopping basket

delivery notification

manual work-

around

omitted steps

desired outcome or deliverable

user activities

system features

Page 56: Specification-By-Example with Gherkin

Story Map example

Page 57: Specification-By-Example with Gherkin

Sprint 1

Page 58: Specification-By-Example with Gherkin

Sprint 2

Page 59: Specification-By-Example with Gherkin

Sprint 3

Page 60: Specification-By-Example with Gherkin

Sprint 4

Page 61: Specification-By-Example with Gherkin

Dropped Scope

Page 62: Specification-By-Example with Gherkin

Added scope

Page 63: Specification-By-Example with Gherkin

User Stories vs. Features Product/Sprint Backlog

User Story 1 AccCrit 1

AccCrit 2

User Story 2 AccCrit 3

AccCrit 4

Living Documentation

Feature 1

AccCrit 1

AccCrit 2

Feature n AccCrit 4

AccCrit m User Story n

AccCrit 5

AccCrit m

AccCrit 3 AccCrit 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 64: Specification-By-Example with Gherkin

Living documentation • Link business

readable automation from source code to story maps

• Feed execution results into story maps

• Sync Story Story Map requirements with TFS work items

Page 65: Specification-By-Example with Gherkin

Lessons learned

Page 66: Specification-By-Example with Gherkin

Collaboration over specification

Documentation after conversation • Collaborative discovery • Should trigger new questions • Infinite number of examples • Readability and ability to automate

Page 67: Specification-By-Example with Gherkin

Level of automation

Controller

Business Layer

Data Layer

Model

View

Browser automation

Trigger behavior through controller

Assert behavior on model, db, ..

Setup pre-conditions through service interfaces

Out-of-process

In-process

Page 68: Specification-By-Example with Gherkin

Test execution performance

• Grouping tests – Current WIP

– Completed work

• Database – In-memory

– Templates for setup

• Parallel execution

• Smart execution order

• Level of automation

Page 69: Specification-By-Example with Gherkin

Internal vs. external DSL

Example Source: Liz Keogh https://github.com/lunivore/tictactoe-java/blob/master/ scenarios/com/lunivore/tictactoe/scenarios/Three_in_a_row_wins.java

Page 70: Specification-By-Example with Gherkin

Non-functional acceptance criteria

Given there are 100,000 users registered on the system

When I create a new account

Then I should be taken to my dashboard within 5ms

When 1000 users are hitting the homepage simultaneously Then each user should get a response within 2ms

Matt Wynne http://blog.mattwynne.net/2012/03/13/using-cucumber-for-load-testing

Page 71: Specification-By-Example with Gherkin

Tools

Page 72: Specification-By-Example with Gherkin

Gherkin automation tools

www.cukes.info

www.behat.org

www.specflow.org

Ruby, Java, JavaScript, C++

.NET, Mono, Silverlight, WP7

PHP

Page 73: Specification-By-Example with Gherkin
Page 74: Specification-By-Example with Gherkin
Page 75: Specification-By-Example with Gherkin

Books

Bridiging the Communication Gap Gojko Adzic

Specification by Example Gojko Adzic

Explore It! Elisabeth Hendrickson

Exploratory Software Testing James Whittaker

Page 76: Specification-By-Example with Gherkin

Summary

Specification-by-example

• Collaborative discovery and specification

• Impact on development and test

• Combine with other agile reqmt methods

• Can be supported by tools

Page 77: Specification-By-Example with Gherkin

Questions

Got curious about Specification-By-Example?

Learned something new about using SpecFlow?

Christian Hassa, TechTalk ([email protected], @chr99ha)

Join the BoF Session „Specification-By-Example (ATDD, BDD) in practice“ Today at 15h15 (right after this talk)