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.
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 :
And yes, JsUnit do handle timeouts : Simulating Time in jsUnit Tests
Im 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've written an Ant task which uses Phantom JS, a headless webkit browser, to run QUnit html test files within an Ant build process. It can also fail the build if any tests fail.
https://github.com/philmander/ant-jstestrunner
I've published a little library for verifying browser-dependent JavaScript tests without having to use a browser. It is a node.js module that uses zombie.js to load the test page and inspect the results. I've wrote about it on my blog. Here is what the automation looks like:
I recently read an article by Bruno using JsUnit and creating a JsMock framework on top of that... very interesting. I'm thinking of using his work to start unit testing my Javascript code.
Mock Javascript or How to unit test Javascript outside the Browser environment
I just got Hudson CI to run JasmineBDD (headless), at least for pure javascript unit testing.
(Hudson running Java via shell, running Envjs, running JasmineBDD.)
I haven't got it to play nice with a big library yet, though, like prototype.