aslak hellesoy executable user stories r spec bdd

27
Behaviour-Driven Development Writing software that matters Aslak Hellesøy - Chief Scientist - BEKK

Upload: deimos

Post on 06-May-2015

4.641 views

Category:

Business


1 download

TRANSCRIPT

Page 1: Aslak Hellesoy Executable User Stories R Spec Bdd

Behaviour-Driven DevelopmentWriting software that matters

Aslak Hellesøy - Chief Scientist - BEKK

Page 2: Aslak Hellesoy Executable User Stories R Spec Bdd

2

Dual audience

Stakeholders

Programmers

Page 3: Aslak Hellesoy Executable User Stories R Spec Bdd

Origin and inspiration

JBehaveDan NorthChris Matts

Test Driven Development

Kent Beck

FITWard

Cunningham

User StoriesMike Cohn

Example Driven DevelopmentBrian Marick

Chelimsky, Hellesøy, Takita, Astels, Baker

Connextra StoriesSeveral

Domain Driven Design

Eric Evans

Acceptance-Test Driven

Planning

Page 4: Aslak Hellesoy Executable User Stories R Spec Bdd

4

Software development is all about delivering

business value

Page 5: Aslak Hellesoy Executable User Stories R Spec Bdd

What’s being used

Source: CHAOS report

Page 6: Aslak Hellesoy Executable User Stories R Spec Bdd

Where errors are introduced

Source: CHAOS report

Page 7: Aslak Hellesoy Executable User Stories R Spec Bdd
Page 8: Aslak Hellesoy Executable User Stories R Spec Bdd

8

BDD: Business value

Page 9: Aslak Hellesoy Executable User Stories R Spec Bdd
Page 10: Aslak Hellesoy Executable User Stories R Spec Bdd

10

Ubiqutous Language

Page 11: Aslak Hellesoy Executable User Stories R Spec Bdd

BDD User Stories

Withdraw Cash

As an Account Holder

I want to withdraw cash in an ATM

So that I can get cash when the bank

is closed

Role

Operation

Business value1

Page 12: Aslak Hellesoy Executable User Stories R Spec Bdd

Origin: Connextra

Page 13: Aslak Hellesoy Executable User Stories R Spec Bdd

13

Challenge:Common understanding

of “Done”

Page 14: Aslak Hellesoy Executable User Stories R Spec Bdd

BDD Scenarios

Business value

1

Given I have £200 in my accountWhen I ask to withdraw £20Then I should be given £20And my balance should be £180

Page 15: Aslak Hellesoy Executable User Stories R Spec Bdd

ATDPAcceptance-Test Driven Planning

WriteScenarios

Product Backlog

IterationPlanning

Iteration N (end) Iteration N+1 (start)

Page 16: Aslak Hellesoy Executable User Stories R Spec Bdd

TDD

Red

Green

Refactor

Make the

test pass

Write a

failing

test

Write a

passing test

1 2

3?

Page 17: Aslak Hellesoy Executable User Stories R Spec Bdd

Developers don’t know...

• Where to start

• What to test

• What not to test

• How much to test in one go

• What to call tests

• How to fix a broken test

• That TDD is about design

Page 18: Aslak Hellesoy Executable User Stories R Spec Bdd

Outside-In

2

3

4

5

1

Page 19: Aslak Hellesoy Executable User Stories R Spec Bdd
Page 20: Aslak Hellesoy Executable User Stories R Spec Bdd

0

10,000

20,000

30,000

40,000

June 2007 February 2008

Downloads

0

25

50

75

100

June 2007 February 2008

Contributors

0

10

20

30

40

June 2007 February 2008

RubyForge rank

0

828.25

1,656.50

2,484.75

3,313.00

June 2007 February 2008

SVN commits

Page 21: Aslak Hellesoy Executable User Stories R Spec Bdd

JRuby << RSpec

Page 22: Aslak Hellesoy Executable User Stories R Spec Bdd

RSpec consists of 2 parts

Story Framework

Example Framework

Page 23: Aslak Hellesoy Executable User Stories R Spec Bdd

Story: Log in

As a Project contributor I want to log in So that I can see what projects I have access to Scenario: User provides wrong credentials Given I am on the login page When I log in with login nobody and password useless Then I should be informed that my password is incorrect And I should not see aslak.hellesoy on the page

Scenario: User provides correct credentials Given I am on the login page When I log in with login aslak.hellesoy and password temporary Then I should see aslak.hellesoy on the page And I should have the opportunity to log out

RSpec User Stories

Page 24: Aslak Hellesoy Executable User Stories R Spec Bdd

require 'bowling'

describe Bowling do before(:each) do @bowling = Bowling.new end

it "should score 0 for gutter game" do 20.times { @bowling.hit(0) } @bowling.score.should == 0 endend

RSpec Examples

Page 25: Aslak Hellesoy Executable User Stories R Spec Bdd

Outside-In

2

3

4

5

Story: Withdraw Money

As an account holder

I want to withdraw money

So that I can get cash when the bank is closed

Scenario: Overdraft account

Given an account with -1000 kr

When I ask for 200 kr

Given the balance should be -1000 kr

1

describe Bank do

it "should not be creatable with negative balance" do

lambda do

Bank.new(-9)

end.should(raise_error("Negative balance"))

end

end

Page 26: Aslak Hellesoy Executable User Stories R Spec Bdd

Summary

• As a <Role>, I want <Operation> So that <Business value>

• Given <Known state>, When I <Action>, Then <Expected outcome>

• Work Outside-in in the layer onion

• Write scenarios and tests bottom up (start with outcome)

• Tests are sentences

Page 27: Aslak Hellesoy Executable User Stories R Spec Bdd

References

• http://behaviour-driven.org/

• http://dannorth.net/introducing-bdd/

• http://dannorth.net/whats-in-a-story/

• http://rspec.info/

• http://jtestr.codehaus.org/

• http://jruby.codehaus.org/

• http://blog.aslakhellesoy.com/