Automated unit testing with JavaScript

There are many JavaScript unit test framework out there (JSUnit, scriptaculous, ...), but JSUnit is the only one I know that may be used with an automated build.

If you are doing 'true' unit test you should not need AJAX support. For example, if you are using an RPC Ajax framework such as DWR, you can easily write a mock function:

   function mockFunction(someArg, callback) {
      var result = ...; // Some treatments
      setTimeout(
function() { callback(result); }, 300 // Some fake latency ); }

And yes, JSUnit does handle timeouts: Simulating Time in JSUnit Tests


I'm a big fan of js-test-driver.

It works well in a CI environment and is able to capture actual browsers for cross-browser testing.


I'm just about to start doing JavaScript TDD on a new project I am working on. My current plan is to use QUnit to do the unit testing. While developing the tests can be run by simply refreshing the test page in a browser.

For continuous integration (and ensuring the tests run in all browsers), I will use Selenium to automatically load the test harness in each browser, and read the result. These tests will be run on every checkin to source control.

I am also going to use JSCoverage to get code coverage analysis of the tests. This will also be automated with Selenium.

I'm currently in the middle of setting this up. I'll update this answer with more exact details once I have the setup hammered out.


Testing tools:

  • qunit
  • JSCoverage
  • Selenium