The Road To Test-Driven Development By Christopher Paulicka Software Engineering Manager
Introduction  <ul><li>Not just what Test-Driven Development is… </li></ul><ul><li>But also how to get to Test-Driven Devel...
Agenda <ul><li>What is Test-Driven Development </li></ul><ul><li>One (Abstract) Road to Test-Driven Development </li></ul>...
Vocabulary <ul><li>Test-Driven Development – TDD </li></ul><ul><li>Extreme Programming - XP </li></ul>
Thanks <ul><li>Perl Mongers for showing up! </li></ul><ul><li>Oversee.net for the nice space </li></ul><ul><li>Michael Lee...
The Three Participants <ul><li>Christopher Paulicka </li></ul><ul><li>Oversee.net </li></ul><ul><li>Perl Mongers </li></ul>
Christopher Paulicka <ul><li>Software Development – 16 years </li></ul><ul><li>Testing – 10 years </li></ul><ul><li>Perl –...
Oversee Development Environment <ul><li>Agile/Scrum </li></ul><ul><li>Perforce </li></ul><ul><li>Linux/Apache/MySQL/Perl, ...
Perl Mongers <ul><li>Perl aficionados </li></ul><ul><li>Please ask questions at any time </li></ul><ul><li>What’s your tes...
What is TDD <ul><li>TDD is old, but kind of new </li></ul><ul><li>Test first, but still follow requirements </li></ul><ul>...
Important to Know <ul><li>History of TDD in Extreme Programming </li></ul><ul><li>History of Scrum at Oversee </li></ul>
Software Development Methodologies <ul><li>Hack </li></ul><ul><li>Waterfall </li></ul><ul><li>Agile </li></ul>
Waterfall Development <ul><li>Requirements </li></ul><ul><li>Design </li></ul><ul><li>Implement </li></ul><ul><li>Test </l...
Waterfall Costs <ul><li>Rigid design </li></ul><ul><li>High change costs </li></ul><ul><li>Requires expert designers up fr...
Examples of Agile Methodologies <ul><li>Extreme Programming </li></ul><ul><li>Scrum </li></ul><ul><li>Crystal Clear </li><...
Extreme Programming <ul><li>Test-Driven Development </li></ul><ul><li>Continuous Integration </li></ul><ul><li>Pair Progra...
Cost of Feedback
Test-Driven Development <ul><li>Pick a Feature </li></ul><ul><li>Write a Test for that Feature </li></ul><ul><li>Run all T...
A Bit More About Refactoring <ul><li>Refactor the Code </li></ul><ul><li>Refactor the Tests </li></ul><ul><li>Refactor the...
Who owns testing? <ul><li>QA </li></ul><ul><li>Deploy </li></ul><ul><li>Systems </li></ul><ul><li>Development </li></ul>
Types of Testing <ul><li>Requirements Tests </li></ul><ul><li>Integration Tests </li></ul><ul><li>System Tests </li></ul><...
Types of Development Testing <ul><li>Unit Tests </li></ul><ul><li>Regression Tests </li></ul>
One Possible Road to TDD <ul><li>Test to Verify </li></ul><ul><li>Test for Regression </li></ul><ul><li>Test for Design </...
Test To Verify <ul><li>Problem arises </li></ul><ul><li>Write throw away test </li></ul><ul><li>Disposable code modificati...
Why Do We Do That? <ul><li>Habit </li></ul><ul><li>Speed </li></ul><ul><li>Anticipation (almost done…) </li></ul>
Test for Regression <ul><li>Problem arises </li></ul><ul><li>Write reusable test that duplicates problem </li></ul><ul><li...
Good, but Good enough? <ul><li>Bug driven  </li></ul><ul><li>Prevents regressions </li></ul><ul><li>Run tests anytime in d...
Test for Design <ul><li>Design API </li></ul><ul><li>Write Code </li></ul><ul><li>Write Tests </li></ul><ul><li>Refactor <...
Development Test Processes <ul><li>Piece-wise Test Last </li></ul><ul><li>Lump-sum Test Last </li></ul><ul><li>Test First ...
Test-Driven Development <ul><li>As Beck said in XP </li></ul><ul><ul><li>Good Rules, lead to  </li></ul></ul><ul><ul><li>G...
Rules <ul><li>Write code only when test fails </li></ul><ul><li>Eliminate duplication afterwards </li></ul>
Behaviors <ul><li>Organic Design </li></ul><ul><li>Writing own tests </li></ul><ul><li>Rapid response </li></ul><ul><li>Mo...
Good Unit Tests <ul><li>Run fast </li></ul><ul><li>Run in isolation </li></ul><ul><li>Easy to understand </li></ul><ul><li...
Your Road To TDD <ul><li>Why TDD </li></ul><ul><li>Cost/Benefit Analysis </li></ul><ul><li>How To Start </li></ul>
Why Test Driven Design <ul><li>Tests as Use Cases </li></ul><ul><li>Tests as Documentation </li></ul><ul><li>Tests as Desi...
Possible reasons to avoid TDD <ul><li>Tests are programmer focused </li></ul><ul><li>May not be requirement focused </li><...
Cost/Benefit of TDD <ul><li>Industry Analysis </li></ul><ul><li>Personal Analysis </li></ul>
Benefits - Industry Analysis <ul><li>Reduce development lead-time significantly </li></ul><ul><li>Programmers that write t...
Benefits – Industry Analysis (cont) <ul><li>Programmers tests interface first, then code </li></ul><ul><li>Shorter impleme...
Costs – Industry Analysis <ul><li>More code </li></ul><ul><ul><li>Though higher productivity with TDD </li></ul></ul><ul><...
Metrics – Industry Analysis <ul><li>TDD code passed 18 - 50% more external  test  cases than control group code </li></ul>...
Metrics – Industry Analysis (cont) <ul><li>TDD has 163% more asserts/module </li></ul><ul><li>TDD 2-3x higher test coverag...
Subjective – Industry Analysis <ul><li>After the study, when asked: </li></ul><ul><li>TDD would stick with TDD </li></ul><...
Benefits – Personal Analysis <ul><li>Senior/Junior Developer Interaction </li></ul><ul><ul><li>Senior approve tests/API </...
Costs – Personal Analysis <ul><li>More code </li></ul><ul><ul><li>Though happier with more feedback </li></ul></ul><ul><li...
How To Start <ul><li>Believe in Testing </li></ul><ul><li>Test Framework </li></ul><ul><li>Test Coverage </li></ul><ul><li...
Believe in Testing <ul><li>If it's worth building, it's worth testing. </li></ul><ul><li>If it's not worth testing, why ar...
Test Frameworks <ul><li>Perl has a lot… </li></ul><ul><li>Test::Simple </li></ul><ul><li>Test::More </li></ul><ul><li>Test...
Test Coverage <ul><li>Provide metrics </li></ul><ul><li>Devel::Cover </li></ul>
Write Tests First <ul><li>Code review tests </li></ul><ul><li>Pair program tests </li></ul><ul><li>Always ask, “Where’s th...
Be Aware! <ul><li>You are now becoming a test expert! </li></ul><ul><li>TDD Antipatterns </li></ul><ul><li>Don’t test just...
My Road To Test-Driven Development <ul><li>Hewlett-Packard EMSO </li></ul><ul><li>Idealab </li></ul><ul><ul><li>X1 </li></...
Lessons from Hewlett-Packard <ul><li>Tests are nowhere near perfect </li></ul><ul><li>Tests can prove your point </li></ul...
Tests are nowhere near perfect <ul><li>500000 lines of code </li></ul><ul><li>Hundreds of feature tests working </li></ul>...
Tests can prove your point <ul><li>No one wanted to believe it </li></ul><ul><li>The product needed to ship </li></ul><ul>...
Lessons from X1 <ul><li>Good Test Framework </li></ul><ul><li>Keep each other honest </li></ul>
Good Test Framework <ul><li>Test::Unit </li></ul><ul><li>WWW::Mechanize </li></ul><ul><li>DBI </li></ul><ul><ul><li>No Moc...
Keep each other honest <ul><li>Test First, not test eventually </li></ul><ul><li>Everybody Writes Tests… </li></ul><ul><li...
Lessons from Energy Innovations <ul><li>Cost of Refactoring </li></ul><ul><li>Beware Gold Plating </li></ul><ul><li>It’s e...
Summary <ul><li>Learned about TDD </li></ul><ul><li>Learned about benefits (and costs) of TDD </li></ul><ul><li>Learned fi...
Q&A
Bibliography <ul><li>I would highly recommend “The Object Primer” by Scott W. Ambler, now in it’s third edition. </li></ul...
Bibliography (cont) <ul><li>http://blog.james-carr.org/?p =44 </li></ul><ul><li>http://www.ipd.uka.de/Tichy/uploads/publik...
Bibliography (cont) <ul><li>http://www.sciencedirect.com/science?_ob=ArticleURL&_udi=B75H1-4FC40MJ-2&_user=10&_rdoc=1&_fmt...
Upcoming SlideShare
Loading in...5
×

The Road to Test Driven Development

1,317

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,317
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
46
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "The Road to Test Driven Development"

  1. 1. The Road To Test-Driven Development By Christopher Paulicka Software Engineering Manager
  2. 2. Introduction <ul><li>Not just what Test-Driven Development is… </li></ul><ul><li>But also how to get to Test-Driven Development </li></ul>
  3. 3. Agenda <ul><li>What is Test-Driven Development </li></ul><ul><li>One (Abstract) Road to Test-Driven Development </li></ul><ul><li>Your Road to Test-Driven Development </li></ul><ul><li>My Road to Test-Driven Development </li></ul>
  4. 4. Vocabulary <ul><li>Test-Driven Development – TDD </li></ul><ul><li>Extreme Programming - XP </li></ul>
  5. 5. Thanks <ul><li>Perl Mongers for showing up! </li></ul><ul><li>Oversee.net for the nice space </li></ul><ul><li>Michael Lee, Director of Engineering, for “volunteering” me </li></ul><ul><li>All the development team here at Oversee for feedback </li></ul>
  6. 6. The Three Participants <ul><li>Christopher Paulicka </li></ul><ul><li>Oversee.net </li></ul><ul><li>Perl Mongers </li></ul>
  7. 7. Christopher Paulicka <ul><li>Software Development – 16 years </li></ul><ul><li>Testing – 10 years </li></ul><ul><li>Perl – 4 years </li></ul><ul><li>Test-Driven Development – 1 year </li></ul>
  8. 8. Oversee Development Environment <ul><li>Agile/Scrum </li></ul><ul><li>Perforce </li></ul><ul><li>Linux/Apache/MySQL/Perl, RPM </li></ul><ul><li>Mason/Catalyst, DBI </li></ul><ul><li>Test::More, Test::MockObject </li></ul><ul><li>Test::Unit, Test::WWW::Selenium </li></ul><ul><li>Module::Build, CPAN2RPM </li></ul>
  9. 9. Perl Mongers <ul><li>Perl aficionados </li></ul><ul><li>Please ask questions at any time </li></ul><ul><li>What’s your testing experience? </li></ul>
  10. 10. What is TDD <ul><li>TDD is old, but kind of new </li></ul><ul><li>Test first, but still follow requirements </li></ul><ul><li>Part of Agile/XP, but reusable anywhere </li></ul>
  11. 11. Important to Know <ul><li>History of TDD in Extreme Programming </li></ul><ul><li>History of Scrum at Oversee </li></ul>
  12. 12. Software Development Methodologies <ul><li>Hack </li></ul><ul><li>Waterfall </li></ul><ul><li>Agile </li></ul>
  13. 13. Waterfall Development <ul><li>Requirements </li></ul><ul><li>Design </li></ul><ul><li>Implement </li></ul><ul><li>Test </li></ul><ul><li>Maintain </li></ul>
  14. 14. Waterfall Costs <ul><li>Rigid design </li></ul><ul><li>High change costs </li></ul><ul><li>Requires expert designers up front </li></ul>
  15. 15. Examples of Agile Methodologies <ul><li>Extreme Programming </li></ul><ul><li>Scrum </li></ul><ul><li>Crystal Clear </li></ul><ul><li>Feature Driven Development </li></ul><ul><li>Adaptive Software Development </li></ul><ul><li>DSDM </li></ul>
  16. 16. Extreme Programming <ul><li>Test-Driven Development </li></ul><ul><li>Continuous Integration </li></ul><ul><li>Pair Programming </li></ul><ul><li>Refactoring </li></ul>
  17. 17. Cost of Feedback
  18. 18. Test-Driven Development <ul><li>Pick a Feature </li></ul><ul><li>Write a Test for that Feature </li></ul><ul><li>Run all Tests and see new Test Fail </li></ul><ul><li>Write Code for Feature </li></ul><ul><li>Run all Tests and see all Tests Pass </li></ul><ul><li>Refactor </li></ul><ul><li>Repeat </li></ul>
  19. 19. A Bit More About Refactoring <ul><li>Refactor the Code </li></ul><ul><li>Refactor the Tests </li></ul><ul><li>Refactor the Documentation </li></ul><ul><li>Refactor the Design </li></ul>
  20. 20. Who owns testing? <ul><li>QA </li></ul><ul><li>Deploy </li></ul><ul><li>Systems </li></ul><ul><li>Development </li></ul>
  21. 21. Types of Testing <ul><li>Requirements Tests </li></ul><ul><li>Integration Tests </li></ul><ul><li>System Tests </li></ul><ul><li>Development Tests </li></ul>
  22. 22. Types of Development Testing <ul><li>Unit Tests </li></ul><ul><li>Regression Tests </li></ul>
  23. 23. One Possible Road to TDD <ul><li>Test to Verify </li></ul><ul><li>Test for Regression </li></ul><ul><li>Test for Design </li></ul><ul><li>Test-Driven Development </li></ul>
  24. 24. Test To Verify <ul><li>Problem arises </li></ul><ul><li>Write throw away test </li></ul><ul><li>Disposable code modifications </li></ul><ul><ul><li>Logging </li></ul></ul><ul><ul><li>Dumping, etc </li></ul></ul><ul><li>Simple and Fast </li></ul><ul><li>Gone forever… </li></ul>
  25. 25. Why Do We Do That? <ul><li>Habit </li></ul><ul><li>Speed </li></ul><ul><li>Anticipation (almost done…) </li></ul>
  26. 26. Test for Regression <ul><li>Problem arises </li></ul><ul><li>Write reusable test that duplicates problem </li></ul><ul><li>Keep regression test </li></ul><ul><li>Run regressions anytime </li></ul>
  27. 27. Good, but Good enough? <ul><li>Bug driven </li></ul><ul><li>Prevents regressions </li></ul><ul><li>Run tests anytime in development </li></ul><ul><li>Focused late in the curve </li></ul><ul><li>Expects test framework </li></ul>
  28. 28. Test for Design <ul><li>Design API </li></ul><ul><li>Write Code </li></ul><ul><li>Write Tests </li></ul><ul><li>Refactor </li></ul>
  29. 29. Development Test Processes <ul><li>Piece-wise Test Last </li></ul><ul><li>Lump-sum Test Last </li></ul><ul><li>Test First aka TDD </li></ul>
  30. 30. Test-Driven Development <ul><li>As Beck said in XP </li></ul><ul><ul><li>Good Rules, lead to </li></ul></ul><ul><ul><li>Good Behavior, which give </li></ul></ul><ul><ul><li>Good Unit Tests </li></ul></ul>
  31. 31. Rules <ul><li>Write code only when test fails </li></ul><ul><li>Eliminate duplication afterwards </li></ul>
  32. 32. Behaviors <ul><li>Organic Design </li></ul><ul><li>Writing own tests </li></ul><ul><li>Rapid response </li></ul><ul><li>Modular Design </li></ul>
  33. 33. Good Unit Tests <ul><li>Run fast </li></ul><ul><li>Run in isolation </li></ul><ul><li>Easy to understand </li></ul><ul><li>Use real data </li></ul><ul><li>Incremental step (not too large) </li></ul>
  34. 34. Your Road To TDD <ul><li>Why TDD </li></ul><ul><li>Cost/Benefit Analysis </li></ul><ul><li>How To Start </li></ul>
  35. 35. Why Test Driven Design <ul><li>Tests as Use Cases </li></ul><ul><li>Tests as Documentation </li></ul><ul><li>Tests as Design </li></ul>
  36. 36. Possible reasons to avoid TDD <ul><li>Tests are programmer focused </li></ul><ul><li>May not be requirement focused </li></ul><ul><li>Running all tests are slow </li></ul><ul><li>Sprinting </li></ul><ul><li>Refactoring </li></ul><ul><li>Comparing </li></ul>
  37. 37. Cost/Benefit of TDD <ul><li>Industry Analysis </li></ul><ul><li>Personal Analysis </li></ul>
  38. 38. Benefits - Industry Analysis <ul><li>Reduce development lead-time significantly </li></ul><ul><li>Programmers that write tests are more productive </li></ul><ul><li>Rarely use a debugger </li></ul><ul><li>Easy to revert on test failure </li></ul><ul><li>… </li></ul>
  39. 39. Benefits – Industry Analysis (cont) <ul><li>Programmers tests interface first, then code </li></ul><ul><li>Shorter implementation time </li></ul><ul><li>High Code coverage </li></ul><ul><li>Regressions </li></ul><ul><li>More modular code </li></ul>
  40. 40. Costs – Industry Analysis <ul><li>More code </li></ul><ul><ul><li>Though higher productivity with TDD </li></ul></ul><ul><li>Costly test setup </li></ul><ul><ul><li>UI </li></ul></ul><ul><ul><li>DB </li></ul></ul><ul><ul><li>Multithreaded </li></ul></ul><ul><li>Large legacy code bases </li></ul>
  41. 41. Metrics – Industry Analysis <ul><li>TDD code passed 18 - 50% more external test cases than control group code </li></ul><ul><li>TDD code had 10 – 50% less time spent debugging code </li></ul><ul><li>TDD had from 0 - 16% decrease in productivity (in lines of non-test code) </li></ul><ul><li>… </li></ul>
  42. 42. Metrics – Industry Analysis (cont) <ul><li>TDD has 163% more asserts/module </li></ul><ul><li>TDD 2-3x higher test coverage </li></ul><ul><ul><li>line and condition coverage near 100% </li></ul></ul><ul><li>TDD coders spent 13% less time producing solutions that were 12% larger then control (including tests!) </li></ul>
  43. 43. Subjective – Industry Analysis <ul><li>After the study, when asked: </li></ul><ul><li>TDD would stick with TDD </li></ul><ul><li>TLD would go to TDD (60%+) </li></ul><ul><li>No tests would go to TLD </li></ul>
  44. 44. Benefits – Personal Analysis <ul><li>Senior/Junior Developer Interaction </li></ul><ul><ul><li>Senior approve tests/API </li></ul></ul><ul><ul><li>Junior implements API </li></ul></ul><ul><ul><li>Senior code reviews, done </li></ul></ul><ul><li>Tests as Use Cases </li></ul><ul><li>Test Documentation more stable then Code Documentation </li></ul>
  45. 45. Costs – Personal Analysis <ul><li>More code </li></ul><ul><ul><li>Though happier with more feedback </li></ul></ul><ul><li>Costly test setup </li></ul><ul><ul><li>UI - WWW::Mechanize </li></ul></ul><ul><ul><li>DB – Test::MockObject </li></ul></ul><ul><ul><li>Multithreaded - …heh…yes. </li></ul></ul><ul><li>Large Legacy Codebases are painful, but TDD may be very beneficial…it’s a start! </li></ul>
  46. 46. How To Start <ul><li>Believe in Testing </li></ul><ul><li>Test Framework </li></ul><ul><li>Test Coverage </li></ul><ul><li>Write Tests First </li></ul>
  47. 47. Believe in Testing <ul><li>If it's worth building, it's worth testing. </li></ul><ul><li>If it's not worth testing, why are you wasting your time working on it? </li></ul>
  48. 48. Test Frameworks <ul><li>Perl has a lot… </li></ul><ul><li>Test::Simple </li></ul><ul><li>Test::More </li></ul><ul><li>Test::Unit </li></ul>
  49. 49. Test Coverage <ul><li>Provide metrics </li></ul><ul><li>Devel::Cover </li></ul>
  50. 50. Write Tests First <ul><li>Code review tests </li></ul><ul><li>Pair program tests </li></ul><ul><li>Always ask, “Where’s the test?” </li></ul><ul><li>Help make tests easier </li></ul>
  51. 51. Be Aware! <ul><li>You are now becoming a test expert! </li></ul><ul><li>TDD Antipatterns </li></ul><ul><li>Don’t test just to test… </li></ul>
  52. 52. My Road To Test-Driven Development <ul><li>Hewlett-Packard EMSO </li></ul><ul><li>Idealab </li></ul><ul><ul><li>X1 </li></ul></ul><ul><ul><li>Energy Innovations </li></ul></ul>
  53. 53. Lessons from Hewlett-Packard <ul><li>Tests are nowhere near perfect </li></ul><ul><li>Tests can prove your point </li></ul><ul><li>Believe in tests! </li></ul>
  54. 54. Tests are nowhere near perfect <ul><li>500000 lines of code </li></ul><ul><li>Hundreds of feature tests working </li></ul><ul><li>Applications run for 3 days </li></ul><ul><li>I knew it was broken </li></ul>
  55. 55. Tests can prove your point <ul><li>No one wanted to believe it </li></ul><ul><li>The product needed to ship </li></ul><ul><li>Wrote random component creator/messenger/destroyer </li></ul><ul><li>Core dump in less then a millisecond </li></ul><ul><li>Created tests from random iterations </li></ul><ul><li>Fixed hundreds of memory leaks and contention issues </li></ul>
  56. 56. Lessons from X1 <ul><li>Good Test Framework </li></ul><ul><li>Keep each other honest </li></ul>
  57. 57. Good Test Framework <ul><li>Test::Unit </li></ul><ul><li>WWW::Mechanize </li></ul><ul><li>DBI </li></ul><ul><ul><li>No MockObjects </li></ul></ul>
  58. 58. Keep each other honest <ul><li>Test First, not test eventually </li></ul><ul><li>Everybody Writes Tests… </li></ul><ul><li>…but feel free to ask for help </li></ul>
  59. 59. Lessons from Energy Innovations <ul><li>Cost of Refactoring </li></ul><ul><li>Beware Gold Plating </li></ul><ul><li>It’s easy to get lazy… </li></ul>
  60. 60. Summary <ul><li>Learned about TDD </li></ul><ul><li>Learned about benefits (and costs) of TDD </li></ul><ul><li>Learned first steps towards TDD </li></ul>
  61. 61. Q&A
  62. 62. Bibliography <ul><li>I would highly recommend “The Object Primer” by Scott W. Ambler, now in it’s third edition. </li></ul><ul><li>http://www.agiledata.org/essays/tdd.html </li></ul><ul><li>http://en.wikipedia.org/wiki/Test-driven_development </li></ul><ul><li>http://en.wikipedia.org/wiki/Agile_software_development </li></ul><ul><li>http://en.wikipedia.org/wiki/Continuous_integration </li></ul><ul><li>http://en.wikipedia.org/wiki/Refactoring </li></ul><ul><li>… </li></ul>
  63. 63. Bibliography (cont) <ul><li>http://blog.james-carr.org/?p =44 </li></ul><ul><li>http://www.ipd.uka.de/Tichy/uploads/publikationen/136/MuellerHoefer2007.pdf </li></ul><ul><li>http://www.acm.org/src/subpages/gf_entries_06/DavidJanzen_src_gf06.pdf </li></ul><ul><li>http://utopia.csis.pace.edu/dps/2008/mcapellan/projects/TDD/TDD_Idea_Paper_V04-03.doc </li></ul><ul><li>… </li></ul>
  64. 64. Bibliography (cont) <ul><li>http://www.sciencedirect.com/science?_ob=ArticleURL&_udi=B75H1-4FC40MJ-2&_user=10&_rdoc=1&_fmt=&_orig=search&_sort=d&view=c&_acct=C000050221&_version=1&_urlVersion=0&_userid=10&md5=fbd92b394263506930dfafb31003a916 </li></ul><ul><li>http://aegis.sourceforge.net/ </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×