Behavior Driven Development

114
Behaviour Driven Development Liz Keogh @lunivore

description

Annotated slides from my "Behavior Driven Development" course. Released under Creative Commons share-alike, commercial and derivatives allowed: http://creativecommons.org/licenses/by-sa/3.0/

Transcript of Behavior Driven Development

Page 1: Behavior Driven Development

BehaviourDrivenDevelopment

Liz Keogh@lunivore

Page 2: Behavior Driven Development

Behaviour-Driven Development

Feature Injection

Cynefin and Differentiation

Splitting Stories

Page 3: Behavior Driven Development

BDDuses examples

to illustrate behavior

Page 4: Behavior Driven Development

An Example of an Example

Given Fred has bought a microwaveAnd the microwave cost £100

When we refund the microwaveThen Fred should be refunded £100.

Page 5: Behavior Driven Development

An Example of an Example

Given baby rabbits cost £10When we sell Snowy the Baby RabbitThen the customer should be charged

£10.

Page 6: Behavior Driven Development

Examples

Given a contextWhen an event happens

Then an outcome should occur

Page 7: Behavior Driven Development

“Given Scenario” – an antipattern

Given Fred puts a microwave in the basketAnd the microwave cost £100

When Fred buys the microwaveThen he should be charged £100When we refund the microwave

Then Fred should be refunded £100.

Page 8: Behavior Driven Development

Cucumber

Feature: Addition In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers Scenario: Add two numbers Given I have entered 50 into the calculator And I have entered 70 into the calculator When I press add Then the result should be 120 on the screen

This is what most peopleassociate with BDD

Page 9: Behavior Driven Development
Page 10: Behavior Driven Development

BDD is about having conversations

Page 11: Behavior Driven Development

BDD should make it easyto create software

Page 12: Behavior Driven Development

A scenario is an idea, not a promise

Page 13: Behavior Driven Development

A scenario is an idea, not a promise

Page 14: Behavior Driven Development

Having conversations

is more important thancapturing conversations

is more important thanautomating conversations

Page 15: Behavior Driven Development

Exercise

Think of thebest conversations

you’ve had.What made them awesome?

Page 16: Behavior Driven Development

Entertaining

Learning

Questions

ChallengeDifferentopinions

Uncertainty

Shared context

Newpeople

IdeasSupportCertainty

Page 17: Behavior Driven Development

A storybecause devs love

empty lists

Page 18: Behavior Driven Development

Boring!

Given Fred bought a microwaveAnd has receipt number 1857123

And receipt 1857123 lists it at £100When we scan the receipt

Then the screen should show the list of itemsWhen we select the microwave

And we refund itAnd scan Fred’s credit card

Then Fred should be refunded £100.

Page 19: Behavior Driven Development

Examples

Given a contextWhen an event happens

Then an outcome should occur

Page 20: Behavior Driven Development

Should it?

Page 21: Behavior Driven Development

Make sure you get it right

Assume you got it wrong

Page 22: Behavior Driven Development

Is there a context in whichthis event will createa different outcome?

Page 23: Behavior Driven Development

Examples

Given Fred has bought a microwaveAnd the microwave cost £100

And the microwave was on 10% discountWhen we refund the microwave

Then Fred should be refunded £90.

Page 24: Behavior Driven Development

Examples

Given Fluffy the baby rabbitis 1 ½ months old

When we try to sell FluffyThen we should be told he’s too young

Page 25: Behavior Driven Development

Is this the only outcomethat matters?

If we could achieve it with pixies, would it be enough?

Page 26: Behavior Driven Development

Examples

Given Fred has bought a microwaveAnd the microwave cost £100

When we refund the microwaveThen the microwave should be

added to the stock count.

Page 27: Behavior Driven Development

Examples

Given each rabbit eats an average of20g of carrots a day

When we sell 10 rabbitsAnd 5 rabbits are born

Then our order for carrots shouldgo down by 700g a week

Page 28: Behavior Driven Development

Same scenario?

Then Fred should be refunded £100

Then the microwave should be addedto the stock count

Page 29: Behavior Driven Development

Same scenario?

Then I should be given £20

And £20 should be debitedfrom my account

Page 30: Behavior Driven Development

Then my eyes glaze over…

When we select “baby rabbit” from the list of petsAnd the customer declines all special offersAnd we want a VAT receiptAnd we select payment by credit cardAnd the customer is presentThen the receipt should say £10And we should have £10 more takingsAnd the number of rabbits in stock should decreaseAnd …

Page 31: Behavior Driven Development

Then my eyes glaze over more

When we click the “Pets” drop-downAnd we select “baby rabbits”And we click “No”And we check “VAT receipt”And we click “Pay”And we select “Credit Card”And we click “Yes”And …

Page 32: Behavior Driven Development

Exercise

Come up with two scenarios

withtwo outcomes

from your own work,one of which can be splitand one of which can’t.

(They don’t have to be about software)

Page 33: Behavior Driven Development

And you can keep going…

Given Fred has bought a microwaveAnd the microwave cost £100And the microwave is faulty

When we refund the microwaveThen a fault ticket should be printed.

Page 34: Behavior Driven Development

Exercise

What other benefitscan you think of

that might come fromtalking through

different scenarios?

Page 35: Behavior Driven Development

Acceptance criteria vs. Scenarios

Given Fred has bought a microwaveAnd the microwave cost £100

And the microwave was on 10% discountWhen we refund the microwave

Then Fred should be refunded £90.

Page 36: Behavior Driven Development

Acceptance criteria vs. Scenarios

Given an item was soldwith a discount

When a customer gets a refundThen he should only be refunded

the discounted price.

Page 37: Behavior Driven Development

Acceptance criteria vs. Scenarios

Items should be refundedat the price at which they were sold.

Page 38: Behavior Driven Development

Acceptance criteria vs. Scenarios

Given Fluffy the baby rabbitis 1 ½ months old

When we try to sellFluffy the baby rabbit

Then we should be toldthat he’s too young

Page 39: Behavior Driven Development

Acceptance criteria vs. Scenarios

Given a pet is belowrecommended selling age

When we try to sellthat pet

Then we should be toldthat the pet is too young

Page 40: Behavior Driven Development

Acceptance criteria vs. Scenarios

We shouldn’t be ableto sell pets

younger than therecommended

selling age

Page 41: Behavior Driven Development

Exercise

Can you derive some scenariosfrom these acceptance criteria?

The user should be able to add and remove bold, italics and underlines.

When browsing an item, users should be able to see what other users who browsed the item bought.

Pets shouldn’t be listed for saleuntil they’re old enough.

Page 42: Behavior Driven Development

Feature Injection

Page 43: Behavior Driven Development

Vision

Makes moneySaves money

Protects money

PrimaryStake-holder

Page 44: Behavior Driven Development

Goal

Neededto go liveIncidental

Stake-holder

Page 45: Behavior Driven Development

Capability

Userscan achievea businessoutcome

Business Analyst

Page 46: Behavior Driven Development

Feature

User interfacecomponent

which enablesa capability

UIDesigner

Page 47: Behavior Driven Development

Story

A slice througha featureto enable

faster feedback

Often adeveloper

Page 48: Behavior Driven Development

Scenario

An exampleof how the system

might behavefrom a userperspective

Dev, tester,analyst

Page 49: Behavior Driven Development

Code

Ideas turning intorealityDeveloper

Page 50: Behavior Driven Development

Visi

on

Goa

l

Capa

bilit

y

Feat

ure

Stor

y

Scen

ario

Code

Page 51: Behavior Driven Development

Visi

on

Goa

l

Capa

bilit

y

Feat

ure

Stor

y

Scen

ario

Code

Page 52: Behavior Driven Development

Visi

on

Goa

l

Capa

bilit

y

Feat

ure

Stor

y

Scen

ario

Code

Page 53: Behavior Driven Development

Exercise

Who are your stakeholders?

Page 54: Behavior Driven Development

Examples can help youdiscover

things early

Page 55: Behavior Driven Development

Is there a stakeholder for whomthis application will not meet their goal?

Page 56: Behavior Driven Development

Are all of the stakeholder’s goalsmet by this?

If we could achieve it with pixies, would it be enough?

Page 57: Behavior Driven Development

Traditional

Rework

Developers Testers

Deliberate Discovery skills

Page 58: Behavior Driven Development

BDD

Less Rework

Developers Testers

Deliberate Discovery skills

Testers

Page 59: Behavior Driven Development

1 2 4 5

Page 60: Behavior Driven Development

1 2 3 4 5

Page 61: Behavior Driven Development

1 2 ? 4 5

Page 62: Behavior Driven Development

1 2 : 4 5

Page 63: Behavior Driven Development

Real Options

Options have value.

Options expire.

Never commit earlyunless you know why.

Page 64: Behavior Driven Development

Business Analyst

DeveloperTester

Page 65: Behavior Driven Development

Cynefin and Differentiation

Kuh-nev-vin

Page 66: Behavior Driven Development

The Big Bucket

Page 67: Behavior Driven Development

A Gantt Chart…

1 1 1

3 32 2

1

23

Page 68: Behavior Driven Development

1

1

1

3

3

2

2

…on its side

Page 69: Behavior Driven Development

Backlog1

1

1

3

3

2

2

Page 70: Behavior Driven Development

If a project has no risks,

don’t do it.

Page 71: Behavior Driven Development

Prioritizing for deadline

$$$$$$$$

$$$$$$$$

$$$$$$$$

$$$$$

$$$$$

$$

$$

$$

Shipped (1 year)

Not ShippedDeadline

Page 72: Behavior Driven Development

Minimum Viable Product

$$$$$$$$

$$$$$$$$

$$$$$$$$

$$$$$

$$$$$

$$

$$

$$

Shipped (2 months)

Not Shipped

Not Shipped

Shipped (2 months)

Page 73: Behavior Driven Development

Types of Software

DifferentiatorsCommodities

KatasExpedite

Page 74: Behavior Driven Development

Types of SoftwareSpoilers

Page 75: Behavior Driven Development

Cynefin

Simple

ComplicatedComplex

Chaotic

With thanks toDavid Snowden and Cognitive Edge

Page 76: Behavior Driven Development

Cynefin

With thanks toDavid Snowden and Cognitive Edge

Disorder

Page 77: Behavior Driven Development

Cynefin

Simple

Chaotic

With thanks toDavid Snowden and Cognitive Edge

Page 78: Behavior Driven Development

Cynefin

Breaking thingsdown

Page 79: Behavior Driven Development

Cynefin

Tryingthings

out

Page 80: Behavior Driven Development

BDD works really well……hereish.

Page 81: Behavior Driven Development

Exercise

Help mestop the spammers!

Page 82: Behavior Driven Development

Fractal beauty

Vision

Goal

Goal

Goal

Capability

Capability

Feature

Feature

Feature

Story

Story

Story

Scenario

Scenario

Code

Code

Code

Page 83: Behavior Driven Development

GoalScenario

Goal

Feature

A Real Project

VisionGoal

Capability

Capability

Feature

Feature

Story

Story

Story

Scenario

Code

Code

Code

Whoops,forgot

Oops, didn’t know about

that…Look what I

found!

Don’t need this… Can’t

remember what this was for…

Page 84: Behavior Driven Development

GoalScenario

Goal

Feature

A Real Project

VisionGoal

Capability

Capability

Feature

Feature

Story

Story

Story

Scenario

Code

Code

Code

Whoops,forgot

Oops, didn’t know about

that…Look what I

found!

Don’t need this… Can’t

remember what this was for…

Um

Er…

Oh!

Oh F… Dammit!

Hmm!

That’s funny!

Ooh, look!

Interesting! Sh..!Oops!

Page 85: Behavior Driven Development

We’re uncovering better ways ofdeveloping software by doing it

Vision

Goal

Goal

Goal

Capability

Capability

Feature

Feature

Feature

Story

Story

Story

Scenario

Scenario

Code

Code

Code

Page 86: Behavior Driven Development

We’re discovering how to discover stuff by doing it

Whoops,forgot

Oops, didn’t know about

that…Look what I

found!

Don’t need this…

Can’t remember what this was for…

Um…

Er…

Oh!

Oh F… Dammit!

Hmm!

That’s funny!

Ooh, look!

Interesting!

Sh..!Oops!

Page 87: Behavior Driven Development

Different levels of granularity

Page 88: Behavior Driven Development

Make assmall a commitment

as possiblethen get feedback

Page 89: Behavior Driven Development
Page 90: Behavior Driven Development

Risk (Newest Stuff) First

Vision

Goal

Goal

Goal

Capability

Capability

Feature

Feature

Feature

Story

Story

Story

Scenario

Scenario

Code

Code

Code

Feature

Goal

Capability

ScenarioCode

Story

Page 91: Behavior Driven Development

High-level, risk-first

Page 92: Behavior Driven Development

Sometimes you discoverthat you

don’t know

Page 93: Behavior Driven Development

High-level, risk-first

Page 94: Behavior Driven Development

Exercise

What should your boardlook like now?

Page 95: Behavior Driven Development

Boring!

Given Fred has bought a microwaveAnd the microwave cost £100

When we refund the microwaveThen Fred should be refunded £100.

Page 96: Behavior Driven Development

Interesting!

Given Fred has bought a 120kg fridge-freezer

When we refund the fridge-freezerThen um…

Page 97: Behavior Driven Development

Exercise

Can you derive a more interesting scenariofrom these acceptance criteria?

The user should be able to add and remove bold, italics and underlines.

When browsing an item, users should be able to see what other users who browsed the item bought.

Pets shouldn’t be listed for saleuntil they’re old enough.

Page 98: Behavior Driven Development

Find the examplesyou

can’t find.

Page 99: Behavior Driven Development

If you’ve done it before,you have

expectations.If you’ve never done it,

all you have arehopes.

Page 100: Behavior Driven Development

Splitting featuresinto stories

Page 101: Behavior Driven Development

Fred Buyer999 Letsby AvenueLondonN1 0UC

By Spiking

Fred

Buyer

Save

New

Page 102: Behavior Driven Development

Stabilizing

Page 103: Behavior Driven Development

Walking Skeleton

Page 104: Behavior Driven Development

Walking Skeleton

Page 105: Behavior Driven Development

By Input

Page 106: Behavior Driven Development

By Output

Page 107: Behavior Driven Development

By Behaviour

Page 108: Behavior Driven Development
Page 109: Behavior Driven Development

Expand

With thanks toMichael James

Page 110: Behavior Driven Development

Don’t let your processhide yourignorance.

Page 111: Behavior Driven Development

Theory of Constraints:A Thought Experiment

Page 112: Behavior Driven Development

This is what I learnt

yesterday.

This is what I hope tofind outtoday.

Page 113: Behavior Driven Development

Having conversations

is more important thancapturing conversations

is more important thanautomating conversations

Page 114: Behavior Driven Development

Liz Keoghhttp://lizkeogh.com@lunivore