behaviour-driven developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/rspec_aslak.pdf · test driven...

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

Upload: others

Post on 06-Oct-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

Behaviour-Driven DevelopmentWriting software that matters

Aslak Hellesøy - Chief Scientist - BEKK

Page 2: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

2

Dual audience

Stakeholders

Programmers

Page 3: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

4

Software development is all about delivering

business value

Page 5: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

What’s being used

Source: CHAOS report

Page 6: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

Where errors are introduced

Source: CHAOS report

Page 7: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s
Page 8: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

8

BDD: Business value

Page 9: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s
Page 10: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

10

Ubiqutous Language

Page 11: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

Origin: Connextra

Page 13: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

13

Challenge:Common understanding

of “Done”

Page 14: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

ATDPAcceptance-Test Driven Planning

WriteScenarios

Product Backlog

IterationPlanning

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

Page 16: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

TDD

Red

Green

Refactor

Make the

test pass

Write a

failing

test

Write a

passing test

1 2

3?

Page 17: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

Outside-In

2

3

4

5

1

Page 19: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s
Page 20: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

JRuby << RSpec

Page 22: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

RSpec consists of 2 parts

Story Framework

Example Framework

Page 23: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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: Behaviour-Driven Developmentjaoo.dk/dl/jaoo-ruby-oslo-2008/slides/RSpec_Aslak.pdf · Test Driven Planning. 4 Software development is all about delivering business value. What’s

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/