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

Executable User Stories with RSpec and BDD

Embed Size (px)

DESCRIPTION

Are you writing code that never gets used? Are you struggling to make the code fit your requirements?Behaviour-Driven Development (BDD) is a fresh breathe of air in the agile community, and its primary focus is to deliver software that matters. -For the end users. BDD builds upon several agile tools and practices like Acceptance-Test Driven Planning, Example-Driven Devlopment, FIT, User Stories and TDD, and bring them together in a consistent whole.This presentation will give an introduction to the principles and practices of BDD and demonstrate how you can make your plain text User Stories executable with RSpec's Story Framework. The framework itself is written in Ruby, but it can run against production code written in any programming language.Watch a video at http://www.bestechvideos.com/2009/04/03/executable-user-stories-with-rspec-and-bdd

Citation preview

Page 1: Executable User Stories with RSpec and BDD

Behaviour-Driven DevelopmentWriting software that matters

Aslak Hellesøy - Chief Scientist - BEKK

Page 2: Executable User Stories with RSpec and BDD

2

Dual audience

Stakeholders

Programmers

Page 3: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and BDD

4

Software development is all about delivering

business value

Page 5: Executable User Stories with RSpec and BDD

What’s being used

Source: CHAOS report

Page 6: Executable User Stories with RSpec and BDD

Where errors are introduced

Source: CHAOS report

Page 7: Executable User Stories with RSpec and BDD
Page 8: Executable User Stories with RSpec and BDD

8

BDD: Business value

Page 9: Executable User Stories with RSpec and BDD
Page 10: Executable User Stories with RSpec and BDD

10

Ubiqutous Language

Page 11: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and BDD

Origin: Connextra

Page 13: Executable User Stories with RSpec and BDD

13

Challenge:Common understanding

of “Done”

Page 14: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and BDD

ATDPAcceptance-Test Driven Planning

WriteScenarios

Product Backlog

IterationPlanning

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

Page 16: Executable User Stories with RSpec and BDD

TDD

Red

Green

Refactor

Make the

test pass

Write a

failing

test

Write a

passing test

1 2

3?

Page 17: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and BDD

Outside-In

2

3

4

5

1

Page 19: Executable User Stories with RSpec and BDD
Page 20: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and BDD

JRuby << RSpec

Page 22: Executable User Stories with RSpec and BDD

RSpec consists of 2 parts

Story Framework

Example Framework

Page 23: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and 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: Executable User Stories with RSpec and 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/