Michael Lancaster
@weblancaster
@weblancaster
Senior Interactive Developer
http://www.bymichaellancaster.com/blog/client-side-javascript-unit-tests-for-front-end-developers/
Slide 3
Slide 3 text
“Program testing can be used to show
the presence of bugs, but never to show
their absence!”
Edsger Dijkstra
Slide 4
Slide 4 text
No content
Slide 5
Slide 5 text
So, why unit test at all?
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
NIST report that the relative cost to repair a defect
found in an operational system is 470 to 880 times
the amount to repair a defect found at the start of the
life cycle when requirements are being formulated.
*NIST (National Institute of Standards and Technology)
Write unit test as you code (ideally before)
Test before push
Test in your CI
Slide 17
Slide 17 text
What tools to use?
Slide 18
Slide 18 text
http://karma-runner.github.io/0.13/index.html
Slide 19
Slide 19 text
http://mochajs.org/
Slide 20
Slide 20 text
http://chaijs.com/
Slide 21
Slide 21 text
http://sinonjs.org/
Sinon.js
Slide 22
Slide 22 text
Show me some code
* https://github.com/weblancaster/karma-mocha-chai-sinon
Slide 23
Slide 23 text
Conclusion…
• Make unit tests part of the culture
• Make unit test processes easy
• Unit test your code as you go (ideally before)
• Structure unit tests in 3A (Arrange, Act, Assert)
• Automate all the things