Download presentation
Presentation is loading. Please wait.
Published bySteven Richard Modified over 9 years ago
1
Using Test Driven Development Jon Kruger Email: jon@jonkruger.com Blog: http://jonkruger.com Twitter: JonKruger
2
Explain why you should write unit tests Show you how to write unit tests for JavaScript code Show you Test Driven Development in action!
5
Tests a small unit of functionality Must run fast Isolate external dependencies using mocks and stubs
6
Test that runs against external dependencies (e.g. database, UI, file system) Test that is slow Web tests, load tests, performance tests
7
You will write bad code You (or someone else) will break your code Someone else will need to understand your code No compiler for JavaScript Peace of mind
8
Proof that your code works Fewer bugs (both now and in the future) Peace of mind
10
1. Design Edge cases Separation of concerns 2. Verification 3. Documentation 4. Testable code 5. When you’re “done” your done
11
Get Specs (features or bugs) Write tests Watch ‘em fail Write code Watch ‘em pass Repeat!
12
http://PairProgrammingBot.com
13
?
14
JSUnitJ3Unit QUnitJSSpec YUI TestScrew-Unit JSNUnitscript.aculo.us unit testing TestCaseCrosscheck RhinoUnitjqUnit more?
16
QUnit JSSpec YUI Test Screw-Unit
20
QUnit Basics
23
Untestable JavaScript
24
Test won’t run unless it’s run from a page that contains these elements.
26
Testing this method will pop up an alert box!
28
Unable to test asynchronous AJAX calls.
31
?
44
Get Specs (features or bugs) Write tests Watch ‘em fail Write code Watch ‘em pass Repeat!
46
Need to inject UI elements into the tests
47
I know that my code works I know what my code is supposed to do - tests are my documentation of my code I know that my code will continue to work My classes are well-designed Tests and good design will mean that it will be easier to make changes to the code Peace of mind!
48
Hold yourself to higher standard If your code sucks, then stop writing sucky code. Make quality a priority
49
?
50
QUnit home page http://docs.jquery.com/QUnit Integrating QUnit tests into a continuous integration build http://tinyurl.com/qunitbuild MiniSudoku source code http://jonkruger.com/minisudoku/source.php My blog http://jonkruger.com Send me an email! jon@jonkruger.com Twitter http://twitter.com/jonkruger
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.