Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to TDD - Jason Arhart

Las Vegas Ruby Group
September 26, 2012
340

Introduction to TDD - Jason Arhart

Las Vegas Ruby Group

September 26, 2012
Tweet

Transcript

  1. Ad-Hoc Testing Write some code, then play with it to

    see if it works Thursday, August 1, 13
  2. Ad-Hoc Testing Write some code, then play with it to

    see if it works It’s what developers do naturally Thursday, August 1, 13
  3. Ad-Hoc Testing Write some code, then play with it to

    see if it works It’s what developers do naturally Requires no additional tools or frameworks Thursday, August 1, 13
  4. As you add features, testing becomes cumbersome... ... and test

    coverage becomes random... Ad-Hoc Testing Thursday, August 1, 13
  5. As you add features, testing becomes cumbersome... ... and test

    coverage becomes random... ...making it easy to miss something... Ad-Hoc Testing Thursday, August 1, 13
  6. Observations Effective testing involves repetition Computers are good at repetition

    Humans, not so much Programmers love to automate repetitive tasks Thursday, August 1, 13
  7. Observations Effective testing involves repetition Computers are good at repetition

    Humans, not so much Programmers love to automate repetitive tasks We should automate the tests! Thursday, August 1, 13
  8. • Write a program to do the testing • Entire

    test suite can be run every time Automated Testing Thursday, August 1, 13
  9. • Write a program to do the testing • Entire

    test suite can be run every time • Allows for refactoring Automated Testing Thursday, August 1, 13
  10. • Write a program to do the testing • Entire

    test suite can be run every time • Allows for refactoring • Tests run unobserved and report success or failure Automated Testing Thursday, August 1, 13
  11. • Code is not always easy to test automatically •

    No clear way to test the tests Automated Testing Thursday, August 1, 13
  12. • Code is not always easy to test automatically •

    No clear way to test the tests • Code can still get ahead of test coverage Automated Testing Thursday, August 1, 13
  13. Test-First (TDD) • Turns the “traditional” process on its head

    • Helps ensure that your tests work Thursday, August 1, 13
  14. Test-First (TDD) • Turns the “traditional” process on its head

    • Helps ensure that your tests work • Code is testable from the start Thursday, August 1, 13
  15. Test-First (TDD) • Turns the “traditional” process on its head

    • Helps ensure that your tests work • Code is testable from the start • Focus on behavior Thursday, August 1, 13
  16. Test-First (TDD) • Turns the “traditional” process on its head

    • Helps ensure that your tests work • Code is testable from the start • Focus on behavior • Consistent test coverage Thursday, August 1, 13
  17. TDD Rules Never implement functionality until you have a failing

    test for it. Only write enough of your test to make it fail. Thursday, August 1, 13
  18. TDD Rules Never implement functionality until you have a failing

    test for it. Only write enough of your test to make it fail. Only write enough production code to make your test pass. Thursday, August 1, 13
  19. TDD Rules Never implement functionality until you have a failing

    test for it. Only write enough of your test to make it fail. Only write enough production code to make your test pass. Never refactor unless your tests are passing. Thursday, August 1, 13
  20. Final Thoughts Test-Driven Development is hard... ...but it gets easy

    with practice It takes LOTS of practice Thursday, August 1, 13
  21. Final Thoughts Test-Driven Development is hard... ...but it gets easy

    with practice It takes LOTS of practice Learning TDD on a real project is nearly impossible... Thursday, August 1, 13
  22. Final Thoughts Test-Driven Development is hard... ...but it gets easy

    with practice It takes LOTS of practice Learning TDD on a real project is nearly impossible... ...so how do we practice it? Thursday, August 1, 13
  23. Attributions • “Evolution of the Cylon” Battlestar Galactica © 2009

    Universal Network Television LLC • “Explosion” © Department of Energy Thursday, August 1, 13