Node.js Unit Testing [closed]

Node.js Unit Testing [closed]

Are there any good node.js (server side js) unit testing frameworks currently out there? I’m looking for something a little deeper than the Assert module provided.

Solutions/Answers:

Solution 1:

I ended up using node-unit and am really happy with it.

I was using Expresso originally but the fact that it runs tests in parallel caused a few problems. (For example using database fixtures doesn’t work well in this situation).

Solution 2:

I was also looking for a decent test framework for node and found Mocha. It is the official successor to Expresso and seems very mature.

It allows to plug-in different assertion libraries, it offers reporters for code coverage and other things (you can plug-in your own). It can run sync or async and it has a concise API.

I will give it a try and report back…

EDIT:

After an incredible amount of time dedicated to other projects I finally came back to a Javascript project and had time to play around with mocha. I can seriously recommend using it. The tests read very nicely, integration with gulp is great and tests run very fast. I was able to setup automatic standalone as well as in-browser (browserify) test runs and corresponding code coverage reports in about half a day (most of the time spent on understanding how to use browserify from gulp). To me, mocha seems a very good choice for a testing framework.

Related:  Call a function in an ExtJS XTemplate

UPDATE:

I am still very convinced about Mocha. Integration with chai allows to plugin different assertion styles. You can checkout a working setup in this github project. I am using it with karma now, integrating code coverage report, automatic watchers and good integration with IntelliJ

Solution 3:

I’ve personally only used the assert module, but also find myself wanting more. I’ve looked through many node modules and popular unit testing frameworks are node-unit and should (which is made by the same guy as Expresso (maybe an updated name?)

Vows also looks promising.

Solution 4:

Personally I’ve stuck with Expresso, but there are a bunch of different frameworks out there, accommodating most testing styles.

Joyent has an extensive list; give that a go.

Solution 5:

I have setup with Mocha – there is a great tutorial right here – http://brianstoner.com/blog/testing-in-nodejs-with-mocha/

Solution 6:

vows is a solid unit testing library for node.js but the syntax is tedious.

I’ve written a thin abstraction called vows-fluent which makes the API chainable.

Related:  Finding All Combinations of JavaScript array values

And I’ve written another abstraction, [vows-is] which builds on vows-fluent and exposes a BDD style syntax.

An example would be

var is = require("vows-is");

is.suite("testing is fun").batch()

    .context("is testing fun?")
        .topic.is("yes")
        .vow.it.should.equal("yes")

.suite().run({
    reporter: is.reporter
});

More examples