I’m a big fan of automated unit testing. I don’t always develop test-first, but I do always try to make sure I end up with a good set of tests for whatever code I’m writing. For JavaScript (in the browser), I’ve settled on QUnit as my unit testing framework of choice. It’s easy to use and works well.
Ideally, you’ll have tests that cover every part of the code. For some projects, it’s pretty easy to tell when this is the case. But if you find yourself writing tests for a complex piece of code that didn’t have many (or any) tests beforehand, as I did recently, then it can be good to know exactly how much of the code is being tested, and which bits still need to be exercised through tests. This is where a code coverage tool comes in. Continue reading