I'm trying to incorporate some JavaScript unit testing into my automated build process. Currently JSUnit works well with JUnit, but it seems to be abandonware and lacks good support for AJAX, debugging, and timeouts.
Has anyone had any luck automating (with ANT) a unit testing library such as YUI test, JQuery's QUnit, or jQUnit (http://code.google.com/p/jqunit/)?
Note: I use a custom built AJAX library, so the problem with Dojo's DOH is that it requires you to use their own AJAX function calls and event handlers to work with any AJAX unit testing.
Another JS testing framework that can be run with Ant is CrossCheck. There's an example of running CrossCheck via Ant in the build file for the project.
CrossCheck attempts, with limited success, to emulate a browser, including mock-style implementations of XMLHttpRequest and timeout/interval.
It does not currently handle loading javascript from a web page, though. You have to specify the javascript files that you want to load and test. If you keep all of your JS separated from your HTML, it might work for you.
I am in agreement that jsunit is kind of dying on the vine. We just finished up replacing it with YUI Test.
Similar to the example using qUnit, we are running the tests using Selenium. We are running this test independently from our other selenium tests simply because it does not have the dependencies that the normal UI regression tests have (e.g. deploying the app to a server).
To start out, we have a base javascript file that is included in all of our test html files. This handles setting up the YUI instance, the test runner, the YUI.Test.Suite object as well as the Test.Case. It has a methods that can be accessed via Selenium to run the test suite, check to see if the test runner is still running (results are not available until after it's done), and get the test results (we chose JSON format)
As for the selenium side of things, we used a parameterized test. We run our tests in both IE and FireFox in the data method, parsing the test results into a list of Object arrays with each array containing the browser name, the test file name, the test name, the result (pass, fail or ignore) and the message.
The actual test just asserts the test result. If it is not equal to "pass" then it fails the test with the message returned from the YUI Test result.
I hope this is helpful.
I looked on your question date and back then there were a few good JS testing lib/framework. Today you can find much more and in different focus like TDD, BDD, Assetion and with/without runners support.
There are Many players in this game like Mocha, Chai, QUnit, Jasmine, etc... You can find some more information in this blog about JS/Mobile/web testing...
The project I'm working on uses Js-Test-Driver hosting Jasmine on Chrome 10 with Jasmine-JSTD-Adapter including making use of Code Coverage tests included in JS-Test-Driver. While there are some problems each time we change or update browsers on the CI environment the jasmine tests are running pretty smoothly with only minor issues with ansynchronous tests, but as far as I'm aware these can be worked around using Jasmine Clock but I haven't had a chance to patch them yet.
This is a good evaluation of several testing tools.
JavaScript unit test tools for TDD
I personally prefer https://code.google.com/p/js-test-driver/
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: