Coding With Confidence: Adding TDD to Your Toolset

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Coding With Confidence: Adding TDD to Your Toolset - Presentation Transcript

    1. Coding with Confidence Adding TDD to Your Toolset
    2. image: un-sharp @ flickr
    3. why test?
    4. reduce defects
    5. verify expectations
    6. why test first?
    7. “The metric I, and others I know, have used to judge unit testing is: does it find bugs?” Bill Moorier
    8. kinda.
    9. “When you write unit tests ... you scrutinize, you think, and often you prevent problems without even encountering a test failure.” Michael Feathers
    10. Test-Driven Development
    11. Test-Driven Design
    12. 1. Design the API 2. Make it work 3. Make it clean
    13. cohesion coupling
    14. “As long as you don't change that component's external interfaces, you can be comfortable that you won't cause problems that ripple through the entire system” The Pragmatic Programmer
    15. avoid complicated solutions to simple problems
    16. insurance image: buttepubliclibrary @ flickr
    17. regressions
    18. mess image: locket479 @ flickr
    19. “Consider a building with a few broken windows. If the windows are not repaired, the tendency is for vandals to break more windows” The Atlantic Monthly (1982)
    20. fear image: troyholden @ flickr
    21. “Test-driven development is a way of managing fear during programming” Kent Beck
    22. documentation image: horrgakx @ flickr
    23. 1. Design the API 2. Make it work 3. Make it clean
    24. 1. Design the API write a failing test 2. Make it work 3. Make it clean
    25. 1. Design the API write a failing test 2. Make it work make the test pass 3. Make it clean
    26. 1. Design the API write a failing test 2. Make it work make the test pass 3. Make it clean remove duplication
    27. 1. RED 2. GREEN 3. REFACTOR image: rooreynolds @ flickr
    28. class FabricatedTest < Test::Unit::TestCase def setup File.touch('tempfile') end def teardown FileUtils.rm('tempfile') end def test_should_know_the_number_of_items bag = Bag.new(3) assert_equal 3, bag.item_count end end anatomy
    29. class FabricatedTest < Test::Unit::TestCase Test case def setup File.touch('tempfile') end def teardown FileUtils.rm('tempfile') end def test_should_know_the_number_of_items bag = Bag.new(3) assert_equal 3, bag.item_count end end anatomy
    30. class FabricatedTest < Test::Unit::TestCase Test case def setup Test setup File.touch('tempfile') (run every test) end def teardown FileUtils.rm('tempfile') end def test_should_know_the_number_of_items bag = Bag.new(3) assert_equal 3, bag.item_count end end anatomy
    31. class FabricatedTest < Test::Unit::TestCase Test case def setup Test setup File.touch('tempfile') (run every test) end def teardown Test teardown FileUtils.rm('tempfile') (run every test) end def test_should_know_the_number_of_items bag = Bag.new(3) assert_equal 3, bag.item_count end end anatomy
    32. class FabricatedTest < Test::Unit::TestCase Test case def setup Test setup File.touch('tempfile') (run every test) end def teardown Test teardown FileUtils.rm('tempfile') (run every test) end def test_should_know_the_number_of_items Test bag = Bag.new(3) assert_equal 3, bag.item_count end end anatomy
    33. class FabricatedTest < Test::Unit::TestCase Test case def setup Test setup File.touch('tempfile') (run every test) end def teardown Test teardown FileUtils.rm('tempfile') (run every test) end def test_should_know_the_number_of_items Test bag = Bag.new(3) assert_equal 3, bag.item_count Assertion end end anatomy
    34. image: mediageek @ flickr
    35. Pitfalls
    36. class User attr_accessor :name end class UserTest < Test::Unit::TestCase def test_should_be_able_to_set_name user = User.new user.name = 'Patrick' assert_equal 'Patrick', user.name end end testing language features
    37. class UserTest < Test::Unit::TestCase def test_valid user = User.new assert !user.valid? assert user.errors.on(:name) assert user.errors.on(:username) end end multiple assertions
    38. class Line def initialize(content) @content = content end private def extract(pattern) @content.match(pattern)[1] end end class LineTest < Test::Unit::TestCase def test_extract_should_return_captured_value line = Line.new('This is content') assert_equal 'is', line.send(:extract, /(is)/) end end testing private methods
    39. class UserTest < Test::Unit::TestCase def setup @content = '{"user_name":"reagent","user_id":"12345"}' end def test_should_be_able_to_extract_the_username user = User.new(@content) assert_equal 'reagent', user.username end def test_should_be_able_to_extract_the_user_id user = User.new(@content) assert_equal '12345', user.id end end lack of context
    40. class User attr_writer :name def name @name.strip end end class UserTest < Test::Unit::TestCase def test_should_remove_whitespace_from_name user = User.new user.name = ' Patrick ' assert_equal 'Patrick', user.name end end testing the happy path
    41. TDD is a tool
    42. TDD is not a religion
    43. Resources • Slides / Code: http://github.com/reagent/talks Contact • patrick.reagan@viget.com • http://twitter.com/reagent Rate This Talk • http://speakerrate.com/preagan image: nomeacuerdo @ flickr
    SlideShare Zeitgeist 2009

    + Patrick ReaganPatrick Reagan Nominate

    custom

    189 views, 1 favs, 2 embeds more stats

    Patrick talks about how a test-first strategy has b more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 189
      • 169 on SlideShare
      • 20 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 1
    Most viewed embeds
    • 16 views on http://sneaq.net
    • 4 views on http://speakerrate.com

    more

    All embeds
    • 16 views on http://sneaq.net
    • 4 views on http://speakerrate.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories