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

Test-Driven Development that Feels Great

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.

Toby Ho

April 13, 2013
Tweet

More Decks by Toby Ho

Other Decks in Programming

Transcript

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

    Better Main Event: Man vs Machine!
  2. 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
  3. 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 ) ; } ) ; } ) ;
  4. 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.
  5. Workflow Tips 1. Don't use slow software 2. Autorun your

    tests! 3. Don't switch windows, tile'em 4. Typing fast helps!
  6. 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 ( ) { . . . } )
  7. 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 ( ) { . . . } )
  8. 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.
  9. 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
  10. 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)