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

Test-Driven Development that Feels Great

A333869fa8934ab32efb4e78e7c1dff1?s=47 Toby Ho
April 13, 2013

Test-Driven Development that Feels Great

A lot of people view Test-Driven-Development (TDD) as a rigorous practice that takes a lot of self displine. I will dispel this myth by showing how TDD can be fun, as well as give tips and tricks on how to keep your TDD experience fast, flowing, and enjoyable. I will also do a live coding session showing the way I do TDD.

A333869fa8934ab32efb4e78e7c1dff1?s=128

Toby Ho

April 13, 2013
Tweet

More Decks by Toby Ho

Other Decks in Programming

Transcript

  1. Let's TDD it! Test-Driven Development that Feels Good by Toby

    Ho tobyho.com @airportyh
  2. Toby Ho tobyho.com @airportyh

  3. Got 'Scripts? Test'em

  4. Our Agenda TDD Quick Start Why TDD? Getting Faster and

    Better Main Event: Man vs Machine!
  5. TDD Quick Start!!

  6. How to do TDD 1. Write a test 2. See

    it fail 3. Write some code 4. See it pass 5. Refactor as see fit (optional) 6. Start again at 1
  7. What A Test Looks Like: Jasmine d e s c

    r i b e ( " h e l l o t e s t " , f u n c t i o n ( ) { i t ( ' a d d s 1 a n d 2 t o g e t 3 ' , f u n c t i o n ( ) { e x p e c t ( a d d ( 1 , 2 ) ) . t o E q u a l ( 3 ) ; } ) ; } ) ;
  8. See it in action

  9. Why TDD?

  10. Why TDD? Reduced defect rates Protection against regression Better API

    designs Re-use tests as your specs
  11. I will write unit tests. I will write unit tests.

    I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests.I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests. I will write unit tests.
  12. None
  13. “Pragmatism: do the right thing, if it's easy.”

  14. None
  15. None
  16. Pain

  17. None
  18. Poor Feedback

  19. Good Feedback

  20. Getting Good Feedback

  21. Good Feedback 1: Workflow

  22. Workflow Tips 1. Don't use slow software 2. Autorun your

    tests! 3. Don't switch windows, tile'em 4. Typing fast helps!
  23. Good Feedback 2: Fast Tests

  24. < 1 Second Whatever it takes

  25. Write Lots of Fast Tests, Little to No Slow Tests

  26. Run Test Subsets

  27. Run Individual Test Suite (Mocha) The mocha unit testing framework

    has this great feature called exclusive tests, where if you mark a certain test suite as the "only" test suite, Mocha then will run only this one. d e s c r i b e . o n l y ( ' m y t e s t s u i t e ' , f u n c t i o n ( ) { . . . } )
  28. Run Individual Test Case (Mocha) i t . o n

    l y ( ' m y t e s t c a s e ' , f u n c t i o n ( ) { . . . } )
  29. . o n l y for Jasmine?

  30. Good Feedback 3. Take Small Steps

  31. Smaller Steps -> More Frequent Test Runs

  32. How Small Steps Helps Debugging Context of what you changed

    Easy undo back to last green point
  33. Small Steps is a skill

  34. Rules of Thumb 1. Do one thing at a time.

    2. Always work on passing one test at a time. 3. Don't fight the wall of red head on.
  35. Test Patterns

  36. None
  37. Small Step Test Patterns 1. Child tests 2. Fake it

    'til you make it 3. One to many 4. Isolated change 5. Back up and refactor
  38. Main Event!!! vs

  39. Thank You! Any Questions? Toby Ho tobyho.com @airportyh

  40. References Jasmine (pivotal.github.io/jasmine) Sinon.js (sinonjs.org) Test'em (github.com/airportyh/testem) Mocha (visionmedia.github.io/mocha/) describe.only

    for Mocha (visionmedia.github.io/mocha/#exclusive tests) describe.only for Jasmine (github.com/pivotal/jasmine/pull/309)