Friday, September 30, 2011 9:34 AM Sean Feldman

JavaScript Unit Testing

Recent announcements for Windows 8 development is not including JavaScript with HTML5 has opened up Windows development for more developers. I wanted to see where testing for JavaScript is standing and was surprised at the variety of frameworks out there. Back in the days when I was trying to do web testing with WatiN, it was painful, especially when a browser had to be loaded for those tests. My interest was around JavaScript testing w/o need to load a browser. QUnit looked very good, but it still required an actual browser. Also, in a CI scenario, I wanted to be able to use a command line/tool execution style.

I have ran into Chutzpah test runner. Great wrapper for QUnit executing w/o need for a browser. More than that, it doesn’t require that standard QUnit shell HTML file for output, which makes tests execution simple and straight forward – execute command line test runner on the scripts folder.

Successful tests execution

image

Failed tests execution

image

This is perfect! Not only runs w/o browser, but also nicely fits to run with CI on a server.

The test runner also comes with a Visual Studio addin to run JavaScripts tests within IDE.

This is the one that I found that nailed it for what I needed. Are there other tools that can do the same and more?

Filed under: ,

Comments

# re: JavaScript Unit Testing

Friday, September 30, 2011 5:00 PM by Jon Davis

Personally I find Javascript runtimes that run from .NET to be compelling. You can then apply unit tests from unit testing frameworks that execute as Javascript implementations, such as . Here are some:

node.js - Duh. :) http://nodejs.org/ Runs on Windows now, although I don't know how well. Use with Expresso: visionmedia.github.com/expresso

Jint - http://jint.codeplex.com/

Javascript.NET (V8) - javascriptdotnet.codeplex.com

Javascript via DLR

.. etc. Good luck.

# re: JavaScript Unit Testing

Wednesday, October 05, 2011 9:25 PM by Matthew Manela

I am the creator of Chutzpah. I wanted to chime in to point out one really nice aspect of the approach I took. Since I use a headless version of webkit under the covers, you can effectively test the interaction between your JavaScript code and the DOM.

# re: JavaScript Unit Testing

Wednesday, October 05, 2011 11:08 PM by Sean Feldman

@Mathew,

Thank you for letting me know this.

# re: JavaScript Unit Testing

Wednesday, October 12, 2011 4:35 PM by David

I've had really good success with jasmine (BDD framework) for javascript unit testing.  Apparently it can be run headless: johnbintz.github.com/jasmine-headless-webkit

Cheers,

David