Slide 1

Slide 1 text

Let's TDD it! Test-Driven Development that Feels Good by Toby Ho tobyho.com @airportyh

Slide 2

Slide 2 text

Toby Ho tobyho.com @airportyh

Slide 3

Slide 3 text

Got 'Scripts? Test'em

Slide 4

Slide 4 text

Our Agenda TDD Quick Start Why TDD? Getting Faster and Better Main Event: Man vs Machine!

Slide 5

Slide 5 text

TDD Quick Start!!

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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 ) ; } ) ; } ) ;

Slide 8

Slide 8 text

See it in action

Slide 9

Slide 9 text

Why TDD?

Slide 10

Slide 10 text

Why TDD? Reduced defect rates Protection against regression Better API designs Re-use tests as your specs

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

“Pragmatism: do the right thing, if it's easy.”

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Pain

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Poor Feedback

Slide 19

Slide 19 text

Good Feedback

Slide 20

Slide 20 text

Getting Good Feedback

Slide 21

Slide 21 text

Good Feedback 1: Workflow

Slide 22

Slide 22 text

Workflow Tips 1. Don't use slow software 2. Autorun your tests! 3. Don't switch windows, tile'em 4. Typing fast helps!

Slide 23

Slide 23 text

Good Feedback 2: Fast Tests

Slide 24

Slide 24 text

< 1 Second Whatever it takes

Slide 25

Slide 25 text

Write Lots of Fast Tests, Little to No Slow Tests

Slide 26

Slide 26 text

Run Test Subsets

Slide 27

Slide 27 text

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 ( ) { . . . } )

Slide 28

Slide 28 text

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 ( ) { . . . } )

Slide 29

Slide 29 text

. o n l y for Jasmine?

Slide 30

Slide 30 text

Good Feedback 3. Take Small Steps

Slide 31

Slide 31 text

Smaller Steps -> More Frequent Test Runs

Slide 32

Slide 32 text

How Small Steps Helps Debugging Context of what you changed Easy undo back to last green point

Slide 33

Slide 33 text

Small Steps is a skill

Slide 34

Slide 34 text

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.

Slide 35

Slide 35 text

Test Patterns

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Main Event!!! vs

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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)