• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
824
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
5
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Test Driven Development
    Why I hate it, but really love it.
  • 2. Start with FAIL
  • 3. Make it Green!
  • 4. Make it Pretty (refactor)
    (Not Like this chap)
  • 5. Eh?
    Why???
    How???
    When???
  • 6. WHY TDD?
  • 7. Stability
  • 8. Flexibility
  • 9. Documentation
  • 10. MORE SPEEEEDzzz
  • 11. Design
  • 12. HOW TDD?
    (Disclaimer: Code incoming!)
  • 13. Writing an adding, er.. Thing…
    Failing Test:
    def test_add_1_plus_1
    assert_equal 2, add(1,1)
    end
    Output:
    tdd.rb:6:in `test_add_1_plus_1': undefined method `add' for main:Object (NoMethodError)
    from tdd.rb:9
  • 14. WHATS THE NEXT STEP?
  • 15. Make it pass:
    def add(i,j)
    return 2
    end
    Output:
    Loaded suite TddExample
    Started
    .
    Finished in 0.000455 seconds.
    1 tests, 1 assertions, 0 failures, 0 errors
  • 16. Waait!!
    Why isn’t it just:
    def add(i,j)
    return i+j
    end
  • 17. WHATS THE NEXT STEP?
  • 18. Write another failing test:
    def test_add_1_plus_2
    assert_equal 3, add(1,2)
    End
    Loaded suite TddExample
    Started
    F
    Finished in 0.042739 seconds.
    1) Failure:
    test_add_1_plus_1(TddExample) [tdd.rb:42]:
    <3> expected but was
    <2>.
    1 tests, 1 assertions, 1 failures, 0 errors
  • 19. Make it pass:
    def add(i,j)
    return i+j
    End
    Loaded suite TddExample
    Started
    ..
    Finished in 0.000462 seconds.
    2 tests, 2 assertions, 0 failures, 0 errors
  • 20. All about the baby steps
  • 21. Problems?
  • 22. add(1,2,3)
    Fail.
    add(1,”two”)
    Fail.
  • 23. How do we cope?
  • 24. Any number of arguments?
    First add a test..
    def test_adding_three_arguments
    assert_equal 4, add(1,2,1)
    End
    Make it pass!!
    Add another test!!
    def test_adding_four_arguments
    assert_equal 8, add(1,2,1,4)
    end
  • 25. Refactor
    For the general solution:
    def add(*args)
    return args.inject(0){|sum,n| sum + n}
    End
    Loaded suite TddExample
    Started
    ....
    Finished in 0.000941 seconds.
    4 tests, 4 assertions, 0 failures, 0 errors
  • 26. Dependency Injection
    (This has nothing to do with children)
  • 27. Example:
    class PersonDAO
    def initialize(user, password)
    @data_source = Database.connect(user, password)
    end
    end
    VS
    class PersonDAO
    def initialize(data_source)
    @data_source = data_source
    end
    end
  • 28. Why is this better?
  • 29. And you’re telling me this… why?
  • 30. Start off with a test
    def setup
    @person = FamilGuyDao.new
    end
    def test_return_full_name_is_reginald_von_griffen
    assert_equal "Reginald Von-Griffin", @person.full_name
    end
    #But how do we make it vary? Pass in the name? Pull it from somewhere
    #Lets assume there is some Griffin Family Tree in the sky
    def test_return_full_name_is_stewie_griffin
    assert_equal "Stewie Griffin", @person.full_name
    end
  • 31. For now we’ll pass in the name
  • 32. Next Test….
  • 33. Make it pass…
  • 34. WHATS THE NEXT STEP?
  • 35. The General Case
    Integration faked by Mock object!
  • 36. MAKE IT PASS!!
  • 37. DONE!