Skip to content

Instantly share code, notes, and snippets.

@Raynos

Raynos/review.md Secret

Created May 12, 2012 20:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Raynos/b0382064a4ddac608b8c to your computer and use it in GitHub Desktop.
Save Raynos/b0382064a4ddac608b8c to your computer and use it in GitHub Desktop.
Unit testing library review

Testing libraries

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.


Server-side test libraries

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.

Advantages

  • 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

Disadvantages

  • 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

Comments

  • 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

Disadvantages

  • 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

Advantages

  • Has pretty abstractions build on top of it like api-easy
  • API is slightly more specific so you know what's going on.

Disadvantages

  • 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

Comments

  • 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.

Advantages

  • Is low on complexity

Disadvantages

  • Wraps the assert module rather then allowing you to use it directly

Comments

  • 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

Advantages

  • Written by isaacs
  • low on complexity

Disadvantages

  • Internals are still surprisingly complex
  • always requires a call to end or to plan

Comments

  • output is TAP compliant
  • experimental code coverage
  • no proper browser support although testling is similar

No library

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

Advantages

  • minimal complexity
  • no learning curve

Disadvantages

  • Difficult to write asynchronous unit tests
  • Difficult to output useful test reports

Comments

  • The minimal solution in node. Some people like this

Client-side libraries

It should be noted that mocha, vows and nodeunit from the server-side section also work in browsers


Advantages

  • is used by jQuery

Disadvantages

  • is used by jQuery

Comments

  • has been ported to node
  • mocha has a QUnit API compliant interface so you can use mocha reporters with qunit

Advantages

Disadvantages

Comments

  • has been ported to node

Testing tools

The following a set of useful tools that generally distribute tests

soda

selenium

testling

zombie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment