Search code examples
javascriptjqueryunit-testingantautomation

Automated unit testing with JavaScript


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?

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.


Solution

  • 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