Ant Tasks

The build.xml Ant file contains several targets. 4 of these targets are used when running the JsUnit server (the others are for building the jsunit.jar - see Installing JsUnit). These targets provide a way to execute the various functions provided by the JsUnit server.

Running a test suite on multiple browsers on the local machine

To run your test suite, invoke the "standalone_test" Ant target by executing "ant standalone_test". This executes a JUnit test called net.jsunit.Standalone test, which opens each browser specified in the browserFileNames property on the URL specified in the url property. When opened, each browser automatically runs your test suite because "autoRun=true" is in the query string. When the browser has finished the run, it submits the results to the JsUnit server because the "submitresults=true" is in the query string.

If any test in your suite fails on any browser, the JUnit test will fail, specifying which browser failed. Otherwise the JUnit test suceeds. This success or failure is passed back to the Ant task, so the Ant "build" fails or suceeds accordingly.

The JsUnit server logs the results from each run in an XML file in the directory specified in the logs property. By default, the filename is the current time in milliseconds followed by ".xml". You can specify the filename using the "resultId" query string parameter (see Standard Query Strings). For more details on logging, see Server Logging.

Running a test suite on multiple remote machines

To run tests on remote machines, invoke the "distributed_test" Ant target by executing "ant distributed_test". This will invoke a JUnit test called net.jsunit.DistributedTest, which "hits" the "runner" servlet on each remote machine specified in the remoteMachineURLs property. When the runner servlet receives this request, it runs net.jsunit.Standalone test, which executes its jsunit test on each of its browsers. If any test fails in any browser on any remote machine, this test will fail, and propogate its failure back through Ant, giving the URL of the remote machine that failed. Otherwise the test suceeds. So, as with the standalone_test target, the Ant "build" fails or suceeds according to the JUnit test.

Starting and stopping the JsUnit Server manually

When setting up a "remote" machine that will be told by a central machine to run its JsUnit tests, you will need to start a JsUnit server. To do this, invoke the "start_server" task by executing "ant start_server". To stop the server, invoke the "stop_server" task by executing "ant stop_server".