Behaviour-Driven Development Writing software that matters Aslak - - PowerPoint PPT Presentation

behaviour driven development
SMART_READER_LITE
LIVE PREVIEW

Behaviour-Driven Development Writing software that matters Aslak - - PowerPoint PPT Presentation

Behaviour-Driven Development Writing software that matters Aslak Hellesy - Chief Scientist - BEKK Stakeholders Programmers Dual audience 2 Origin and inspiration JBehave Test Driven FIT Dan North Development Ward Chris Matts Kent


slide-1
SLIDE 1

Behaviour-Driven Development

Writing software that matters Aslak Hellesøy - Chief Scientist - BEKK

slide-2
SLIDE 2

2

Dual audience Stakeholders Programmers

slide-3
SLIDE 3

Origin and inspiration

JBehave Dan North Chris Matts Test Driven Development Kent Beck FIT Ward Cunningham User Stories Mike Cohn Example Driven Development Brian Marick Chelimsky, Hellesøy, Takita, Astels, Baker Connextra Stories Several Domain Driven Design Eric Evans Acceptance- Test Driven Planning

slide-4
SLIDE 4

4

Software development is all about delivering business value

slide-5
SLIDE 5

What’s being used Source: CHAOS report

slide-6
SLIDE 6

Where errors are introduced Source: CHAOS report

slide-7
SLIDE 7
slide-8
SLIDE 8

8

BDD: Business value

slide-9
SLIDE 9
slide-10
SLIDE 10

10

Ubiqutous Language

slide-11
SLIDE 11

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 value

1

slide-12
SLIDE 12

Origin: Connextra

slide-13
SLIDE 13

13

Challenge: Common understanding

  • f “Done”
slide-14
SLIDE 14

BDD Scenarios

Business value

1

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

slide-15
SLIDE 15

ATDP

Acceptance-Test Driven Planning

Write Scenarios

Product Backlog

Iteration Planning

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

slide-16
SLIDE 16

TDD

Red Green Refactor Make the test pass Write a failing test Write a passing test 1 2 3 ?

slide-17
SLIDE 17

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
slide-18
SLIDE 18

Outside-In

2 3 4 5 1

slide-19
SLIDE 19
slide-20
SLIDE 20

10,000 20,000 30,000 40,000 June 2007 February 2008 Downloads 25 50 75 100 June 2007 February 2008 Contributors 10 20 30 40 June 2007 February 2008 RubyForge rank 828.25 1,656.50 2,484.75 3,313.00 June 2007 February 2008 SVN commits

slide-21
SLIDE 21

JRuby << RSpec

slide-22
SLIDE 22

RSpec consists of 2 parts

Story Framework Example Framework

slide-23
SLIDE 23

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

slide-24
SLIDE 24

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 end end

RSpec Examples

slide-25
SLIDE 25

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
slide-26
SLIDE 26

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
slide-27
SLIDE 27

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/