1 / 64

The Road To Test-Driven Development

The Road To Test-Driven Development By Christopher Paulicka Software Engineering Manager Introduction Not just what Test-Driven Development is… But also how to get to Test-Driven Development Agenda What is Test-Driven Development One (Abstract) Road to Test-Driven Development

oshin
Download Presentation

The Road To Test-Driven Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Road To Test-Driven Development By Christopher Paulicka Software Engineering Manager Copyright Oversee.net 2008

  2. Introduction • Not just what Test-Driven Development is… • But also how to get to Test-Driven Development Copyright Oversee.net 2008

  3. Agenda • What is Test-Driven Development • One (Abstract) Road to Test-Driven Development • Your Road to Test-Driven Development • My Road to Test-Driven Development Copyright Oversee.net 2008

  4. Vocabulary • Test-Driven Development – TDD • Extreme Programming - XP Copyright Oversee.net 2008

  5. Thanks • Perl Mongers for showing up! • Oversee.net for the nice space • Michael Lee, Director of Engineering, for “volunteering” me • All the development team here at Oversee for feedback Copyright Oversee.net 2008

  6. The Three Participants • Christopher Paulicka • Oversee.net • Perl Mongers Copyright Oversee.net 2008

  7. Christopher Paulicka • Software Development – 16 years • Testing – 10 years • Perl – 4 years • Test-Driven Development – 1 year Copyright Oversee.net 2008

  8. Oversee Development Environment • Agile/Scrum • Perforce • Linux/Apache/MySQL/Perl, RPM • Mason/Catalyst, DBI • Test::More, Test::MockObject • Test::Unit, Test::WWW::Selenium • Module::Build, CPAN2RPM Copyright Oversee.net 2008

  9. Perl Mongers • Perl aficionados • Please ask questions at any time • What’s your testing experience? Copyright Oversee.net 2008

  10. What is TDD • TDD is old, but kind of new • Test first, but still follow requirements • Part of Agile/XP, but reusable anywhere Copyright Oversee.net 2008

  11. Important to Know • History of TDD in Extreme Programming • History of Scrum at Oversee Copyright Oversee.net 2008

  12. Software Development Methodologies • Hack • Waterfall • Agile Copyright Oversee.net 2008

  13. Waterfall Development • Requirements • Design • Implement • Test • Maintain Copyright Oversee.net 2008

  14. Waterfall Costs • Rigid design • High change costs • Requires expert designers up front Copyright Oversee.net 2008

  15. Examples of Agile Methodologies • Extreme Programming • Scrum • Crystal Clear • Feature Driven Development • Adaptive Software Development • DSDM Copyright Oversee.net 2008

  16. Extreme Programming • Test-Driven Development • Continuous Integration • Pair Programming • Refactoring Copyright Oversee.net 2008

  17. Cost of Feedback Copyright Oversee.net 2008

  18. Test-Driven Development • Pick a Feature • Write a Test for that Feature • Run all Tests and see new Test Fail • Write Code for Feature • Run all Tests and see all Tests Pass • Refactor • Repeat Copyright Oversee.net 2008

  19. A Bit More About Refactoring • Refactor the Code • Refactor the Tests • Refactor the Documentation • Refactor the Design Copyright Oversee.net 2008

  20. Who owns testing? • QA • Deploy • Systems • Development Copyright Oversee.net 2008

  21. Types of Testing • Requirements Tests • Integration Tests • System Tests • Development Tests Copyright Oversee.net 2008

  22. Types of Development Testing • Unit Tests • Regression Tests Copyright Oversee.net 2008

  23. One Possible Road to TDD • Test to Verify • Test for Regression • Test for Design • Test-Driven Development Copyright Oversee.net 2008

  24. Test To Verify • Problem arises • Write throw away test • Disposable code modifications • Logging • Dumping, etc • Simple and Fast • Gone forever… Copyright Oversee.net 2008

  25. Why Do We Do That? • Habit • Speed • Anticipation (almost done…) Copyright Oversee.net 2008

  26. Test for Regression • Problem arises • Write reusable test that duplicates problem • Keep regression test • Run regressions anytime Copyright Oversee.net 2008

  27. Good, but Good enough? • Bug driven • Prevents regressions • Run tests anytime in development • Focused late in the curve • Expects test framework Copyright Oversee.net 2008

  28. Test for Design • Design API • Write Code • Write Tests • Refactor Copyright Oversee.net 2008

  29. Development Test Processes • Piece-wise Test Last • Lump-sum Test Last • Test First aka TDD Copyright Oversee.net 2008

  30. Test-Driven Development • As Beck said in XP • Good Rules, lead to • Good Behavior, which give • Good Unit Tests Copyright Oversee.net 2008

  31. Rules • Write code only when test fails • Eliminate duplication afterwards Copyright Oversee.net 2008

  32. Behaviors • Organic Design • Writing own tests • Rapid response • Modular Design Copyright Oversee.net 2008

  33. Good Unit Tests • Run fast • Run in isolation • Easy to understand • Use real data • Incremental step (not too large) Copyright Oversee.net 2008

  34. Your Road To TDD • Why TDD • Cost/Benefit Analysis • How To Start Copyright Oversee.net 2008

  35. Why Test Driven Design • Tests as Use Cases • Tests as Documentation • Tests as Design Copyright Oversee.net 2008

  36. Possible reasons to avoid TDD • Tests are programmer focused • May not be requirement focused • Running all tests are slow • Sprinting • Refactoring • Comparing Copyright Oversee.net 2008

  37. Cost/Benefit of TDD • Industry Analysis • Personal Analysis Copyright Oversee.net 2008

  38. Benefits - Industry Analysis • Reduce development lead-time significantly • Programmers that write tests are more productive • Rarely use a debugger • Easy to revert on test failure • … Copyright Oversee.net 2008

  39. Benefits – Industry Analysis (cont) • Programmers tests interface first, then code • Shorter implementation time • High Code coverage • Regressions • More modular code Copyright Oversee.net 2008

  40. Costs – Industry Analysis • More code • Though higher productivity with TDD • Costly test setup • UI • DB • Multithreaded • Large legacy code bases Copyright Oversee.net 2008

  41. Metrics – Industry Analysis • TDD code passed 18 - 50% more external test cases than control group code • TDD code had 10 – 50% less time spent debugging code • TDD had from 0 - 16% decrease in productivity (in lines of non-test code) • … Copyright Oversee.net 2008

  42. Metrics – Industry Analysis (cont) • TDD has 163% more asserts/module • TDD 2-3x higher test coverage • line and condition coverage near 100% • TDD coders spent 13% less time producing solutions that were 12% larger then control (including tests!) Copyright Oversee.net 2008

  43. Subjective – Industry Analysis After the study, when asked: • TDD would stick with TDD • TLD would go to TDD (60%+) • No tests would go to TLD Copyright Oversee.net 2008

  44. Benefits – Personal Analysis • Senior/Junior Developer Interaction • Senior approve tests/API • Junior implements API • Senior code reviews, done • Tests as Use Cases • Test Documentation more stable then Code Documentation Copyright Oversee.net 2008

  45. Costs – Personal Analysis • More code • Though happier with more feedback • Costly test setup • UI - WWW::Mechanize • DB – Test::MockObject • Multithreaded - …heh…yes. • Large Legacy Codebases are painful, but TDD may be very beneficial…it’s a start! Copyright Oversee.net 2008

  46. How To Start • Believe in Testing • Test Framework • Test Coverage • Write Tests First Copyright Oversee.net 2008

  47. Believe in Testing • If it's worth building, it's worth testing. • If it's not worth testing, why are you wasting your time working on it? Copyright Oversee.net 2008

  48. Test Frameworks Perl has a lot… • Test::Simple • Test::More • Test::Unit Copyright Oversee.net 2008

  49. Test Coverage • Provide metrics • Devel::Cover Copyright Oversee.net 2008

  50. Write Tests First • Code review tests • Pair program tests • Always ask, “Where’s the test?” • Help make tests easier Copyright Oversee.net 2008

More Related