What is the best testing framework to use with Node.js? [closed]
I have looked at the rather long list of testing frameworks at https://github.com/ry/node/wiki/modules#testing. What is the experience with these frameworks?
Obviously the ability to run in the browser would be a big bonus, but I'm mainly interested in Node.js. Something with a heavily asynchronous slant would be great.
Update:
Mocha is the best in my opinion.
What is the experience with these frameworks?
I played with expresso which is pretty cool testing framework which also has test-coverage. It has been created by TJ Holowaychuk who is also the creator of Express.js (insanely fast (and small) server-side JavaScript web development framework built on Node.js and Connect). I recently saw that he also has a cool library called should.js which can be used together with Expresso for a even better testing experience.
Obviously, the ability to run in the browser would be a big bonus
I don't believe it can run in the browser, but I also don't get why you would want to run it inside the browser?
but I'm mainly interested in Node.js. Something with a heavily asynchronous slant would be great.
Quote from the expresso:
The argument passed to each callback is beforeExit, which is typically used to assert that callbacks have been invoked.
You can use beforeExit to test asynchronous functions.
TIP: Follow TJ Holowaychuk on GitHub, because he creates very good open-source code.
I use VowsJS which is easy to use async BDD framework (Behaviour Driven Development) and get the job done.
From what I see lately it's what many chose to test their NPM modules, so I believe so far it's one the best to use.
Some popular testing frameworks that could be used with NodeJS are also those:
- Mocha
- Jasmine
- Expresso (no longer maintained)
- Should
- NodeUnit
- jsUnit
You can also see a list of JavaScript test frameworks here
Few more libs that could help you write better code are those:
- ReadyJS watches your js files and test them with JSHint
- Concrete small continuous integration server
- Jezebel continuous testing for Jasmine
- Nosey not quite there but have a nice roadmap so I keep an eye on it
There is also Bamboo CI Server by Atlassian it automates builds and tests. It is a package for Apache/Tomcat (which sux because it uses Java and that makes it very heavy) also is not free but it has a starter license which costs $10 so I believe it is affordable. It is the most featured of all CI servers I found so far and it supports all unit tests that support xUnit that means that you can run builds/tests for any language with Bamboo.
Another option for CI with NodeJS is Travis which lot of people use for their open source projects, as it says A hosted continuous integration service for the open source community.
There is also a google group discussion with Continuous Integration for Node JS Projects topic.
Based on the asker's comments above, I tried out vows, and it solved a lot of problems I was having with my async testing. Its ability to mix serial and parallel testing is awesome.
Make sure you read the guidance doc carefully, but once you get the hang of it, it's flexible, powerful, and produces nice, clean results.
UPDATE: I would also encourage people to check out should for their asserts. It allows for very flexible, very readable asserts, and is compatible with both Expresso and Vows, and probably most other test frameworks as well.
(I'm posting this as a separate answer just in case people don't notice the comments on Alfred's answer.)
UPDATE 1/7/2015: For what it's worth, I have since switched from Vows to Mocha, and from Should to Chai. Mocha has much better support now for asynchronous tests using promises, and Chai allows for several flexible assert options, including the expect
api, for those who don't like to modify the object prototype.