Introduction to TDD - Jason Arhart

B044a0f039af800f4df09bf3b2465f18?s=47 Las Vegas Ruby Group
September 26, 2012
94

Introduction to TDD - Jason Arhart

B044a0f039af800f4df09bf3b2465f18?s=128

Las Vegas Ruby Group

September 26, 2012
Tweet

Transcript

  1. Introduction to TDD Jason Arhart Thursday, August 1, 13

  2. Test-Driven Development What is Test-Driven Development? Thursday, August 1, 13

  3. Development Process Centered on Testing Thursday, August 1, 13

  4. Development Process Centered on Testing Thursday, August 1, 13

  5. Evolution of Testing Thursday, August 1, 13

  6. Ad-Hoc Testing Thursday, August 1, 13

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

    see if it works Thursday, August 1, 13
  8. 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
  9. 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
  10. As you add features, testing becomes cumbersome... Ad-Hoc Testing Thursday,

    August 1, 13
  11. As you add features, testing becomes cumbersome... ... and test

    coverage becomes random... Ad-Hoc Testing Thursday, August 1, 13
  12. 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
  13. Thursday, August 1, 13

  14. Observations Thursday, August 1, 13

  15. Observations Effective testing involves repetition Thursday, August 1, 13

  16. Observations Effective testing involves repetition Computers are good at repetition

    Thursday, August 1, 13
  17. Observations Effective testing involves repetition Computers are good at repetition

    Humans, not so much Thursday, August 1, 13
  18. Observations Effective testing involves repetition Computers are good at repetition

    Humans, not so much Programmers love to automate repetitive tasks Thursday, August 1, 13
  19. 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
  20. Automated Testing Thursday, August 1, 13

  21. • Write a program to do the testing Automated Testing

    Thursday, August 1, 13
  22. • Write a program to do the testing • Entire

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

    test suite can be run every time • Allows for refactoring Automated Testing Thursday, August 1, 13
  24. • 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
  25. • Code is not always easy to test automatically Automated

    Testing Thursday, August 1, 13
  26. • Code is not always easy to test automatically •

    No clear way to test the tests Automated Testing Thursday, August 1, 13
  27. • 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
  28. Test-First (TDD) Thursday, August 1, 13

  29. Test-First (TDD) • Turns the “traditional” process on its head

    Thursday, August 1, 13
  30. Test-First (TDD) • Turns the “traditional” process on its head

    • Helps ensure that your tests work Thursday, August 1, 13
  31. 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
  32. 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
  33. 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
  34. The TDD Cycle Thursday, August 1, 13

  35. The TDD Cycle Step 1: Write a test... Thursday, August

    1, 13
  36. ...watch it fail Thursday, August 1, 13

  37. The TDD Cycle Step 2: Make the test pass Thursday,

    August 1, 13
  38. Celebrate! Thursday, August 1, 13

  39. The TDD Cycle Step 3: Refactor Thursday, August 1, 13

  40. Make it beautiful Thursday, August 1, 13

  41. Make it beautiful Refactor your tests too! Thursday, August 1,

    13
  42. Repeat Thursday, August 1, 13

  43. TDD Rules Thursday, August 1, 13

  44. TDD Rules Never implement functionality until you have a failing

    test for it. Thursday, August 1, 13
  45. 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
  46. 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
  47. 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
  48. Final Thoughts Thursday, August 1, 13

  49. Final Thoughts Test-Driven Development is hard... Thursday, August 1, 13

  50. Final Thoughts Test-Driven Development is hard... ...but it gets easy

    with practice Thursday, August 1, 13
  51. Final Thoughts Test-Driven Development is hard... ...but it gets easy

    with practice It takes LOTS of practice Thursday, August 1, 13
  52. 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
  53. 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
  54. Kata! Thursday, August 1, 13

  55. Attributions • “Evolution of the Cylon” Battlestar Galactica © 2009

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