There are numerous different libraries and tools available for unit testing. We'll split efforts between server & client-side testing libraries. Then look at tools for automated browser testing.
For server-side libraries, mocha is currently the best of the pack but comes at high complexity
Mocha is the unit testing tool I've used the most successfully. It's a solid tool that works on both the server and the client and has a lot of flexibility. Overall I have little to complain about but I'm looking into lighter alternatives to it.
- lots of high quality applications and libraries written that use mocha unit tests. So there is a wide variety of real world examples of how to use mocha
- has a notion of interfaces, this means it has a wide API choice in how you write your unit tests with the same underlying code. This allows you to pick your favourite test API
- handles asynchronous code cleanly with a single callback
- has before/beforeEach/after/afterEach hooks that are really easy to use
- wide range of unit test output reporters to fit your choice.
- works in the browser
- Has a notion of grep. Which allows you to run certain test or suites based on whether their name matches the grep. This allows you to tag your unit tests with #critical, #fast, #slow, etc and run a subset of the unit tests.
- Allows running the same unit tests on different pieces of code by re-using
this
within suite blocks
- The internals are complex. It's difficult to understand how to write multiple test statements where logic spams across them
- Doesn't cleanly run tests on recursive directies, requires command line hacker to get it to run recursively
- written by TJ. TJ is reputable and writes good tools
- experimental code coverage support
- Auto generates markdown style documentation from the unit test code
This is virtually deprecated. The fact it isn't updated any more is a good reason not to use it
- Has been replaced by mocha
Vows looks good and pretty on paper. But the API is not flexible enough to write readable asynchronous unit tests
- Has pretty abstractions build on top of it like api-easy
- API is slightly more specific so you know what's going on.
- Writing async code is too difficult
- It's difficult to spam logic and share code across multiple test blocks
- you have to create new topics to write asynchronous unit tests
- I build vows-is on top of vows and decided that the vows internals were too volatile / unstable. There were ugly edge cases that needed to be manually fixed and the async unit test capabilities were not good enough
- The original maintainer has left and maintenance has been taken over by nodejitsu
Nodeunit seems to be a rather average unit test library. There is nothing special to be said about it.
- Is low on complexity
- Wraps the assert module rather then allowing you to use it directly
- Supports both node and the browser
- only uses the export style unit test
Node tap is a probably one of the better minimalist unit test libraries. It's also good if you need TAP output
- Written by isaacs
- low on complexity
- Internals are still surprisingly complex
- always requires a call to end or to plan
- output is TAP compliant
- experimental code coverage
- no proper browser support although testling is similar
This is a good solution to use until a choice has been made for unit tests on a project, or if you want to write quick and dirty throw away tests
- minimal complexity
- no learning curve
- Difficult to write asynchronous unit tests
- Difficult to output useful test reports
- The minimal solution in node. Some people like this
It should be noted that mocha, vows and nodeunit from the server-side section also work in browsers
- is used by jQuery
- is used by jQuery
- has been ported to node
- mocha has a QUnit API compliant interface so you can use mocha reporters with qunit
- has been ported to node
The following a set of useful tools that generally distribute tests