Behaviour-Driven Development
Upcoming SlideShare
Loading in...5
×
 

Behaviour-Driven Development

on

  • 4,868 views

Slides from a talk to Web21C SDK team.

Slides from a talk to Web21C SDK team.

Statistics

Views

Total Views
4,868
Views on SlideShare
4,856
Embed Views
12

Actions

Likes
6
Downloads
160
Comments
0

3 Embeds 12

http://www.slideshare.net 8
http://confluence.jnpr.net 2
https://confluence.jnpr.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Short presentation on how BDD evolved, then demo using RSpec.

Behaviour-Driven Development Behaviour-Driven Development Presentation Transcript

  • Behaviour-Driven Development
    • Kerry Buckley
  • Evolution
  • Dirty Hacking View slide
  • Automated Testing View slide
  • Automated Testing class Adder def add a, b a + b end end class AdderTest < Test::Unit::TestCase def test_adder adder = Adder . new assert_equal 4 , adder.add( 2 , 2 ) assert_equal 2 , adder.add( 4 , - 2 ) end end
  • Are You Really Testing Your Code? class Adder def add a, b a + b end end class AdderTest < Test::Unit::TestCase def test_adder assert_equal 4 , 2 + 2 end end
  • Test-First Development
  • Test-First Development Failing tests Start Done Write code Write tests
  • Test-Driven Development
  • Test-Driven Development Failing test Clean code All tests pass Refactor
  • State-Based class DongleTest < Test::Unit::TestCase def test_wibble # Set up test inputs dongle = Dongle . new dongle.addString( &quot;foo&quot; ) dongle.addRemoteResource( &quot; http://foo.com/bar &quot; ) # Exercise functionality under test dongle.wibble! # Verify results are as expected dongle.answer.should == 42 end end
  • Bottom-Up
  • Behaviour-Driven Development
  • Behaviour-Driven Development Verification Specification State-based Interaction-based Bottom-up Outside-in Testing tool Design tool Invention Discovery
  • More Descriptive Test Names class AdderTest < Test::Unit::TestCase def test_should_add_two_positive_numbers assert_equal 4 , Adder . new .add( 2 , 2 ) end def test_should_add_a_positive_and_a_negative_number assert_equal 2 , Adder . new .add( 4 , - 2 ) end end
  • Matchers describe &quot;An adder&quot; do it &quot;should add two positive numbers&quot; do Adder . new .add( 2 , 2 ).should == 4 end it &quot;should add a positive and a negative number&quot; do Adder . new .add( 4 , - 2 ).should == 2 end end
  • Generated Documentation $ spec -f s adder_spec.rb An adder - should add two positive numbers - should add a positive and a negative number Finished in 0.005493 seconds 2 examples, 0 failures
  • More Matcher Examples @string .should == &quot;foo&quot; @array .should_not be_empty @hash .should have_key( :foo ) @object .should be_an_instance_of String lambda { @stack .pop }.should raise_error( StackUnderflowError )
  • Top-Down
  • Interaction-Based
  • Mock Objects
    • Stand-ins for collaborating objects
    • Mock the interface, not a specific object
    • Verify that expected calls are made
    • Not stubs!
    • For your code only!
  • Classicists v Mockists
  • Mock Objects Mock Mock
  • Boundary Objects
  • Integration Testing
  • Further Reading Introducing BDD (Dan North) http: //dannorth . net/introducing-bdd BDD Introduction http: //behaviour-driven .org/Introduction Mock Roles, Not Objects (Freeman, Mackinnon, Pryce, Walnes) http://www. jmock .org/oopsla2004. pdf BDD in Ruby (Dave Astels) http: //blog . daveastels . com/files/BDD_Intro . pdf