212 pdfsam Foundations Of Ajax (2005)

CHAPTER 6 ■ TESTING JAVASCRIPT WITH JSUNIT Working with JsUnit Server Although passing various parameters to the test r...

0 downloads 90 Views 40KB Size
CHAPTER 6 ■ TESTING JAVASCRIPT WITH JSUNIT

Working with JsUnit Server Although passing various parameters to the test runner can make it easier to automate tests, you may soon tire of manually running your tests on a regular basis, especially when you factor in multiple browsers on multiple operating systems. You may also want to keep track of the results of previous runs for auditing or quality assurance purposes. The JsUnit Server seeks to address these issues by providing XML logging of test results, running tests from JUnit or Ant scripts, and running tests from JUnit or Ant on remote machines. JsUnit Server lets you run your entire test suite on your operating system/browser combinations at the press of a button. In addition, in an important step, you can make testing your JavaScript part of your build process by adding it to your Ant script. The JsUnit Server consists of a set of Java servlets that run inside the embeddable Jetty open-source Web server, saving you the hassle of installing and configuring a Web server/servlet container on every machine on which you want to test. Once you’ve configured it, the process really is as simple as pushing a button!

Configuring the Server Before you can take advantage of the JsUnit Server, you need to configure it. You can accomplish this by modifying the build.xml file found in the jsunit folder. At the head of this file, you’ll find a set of properties that you can modify to fit your needs. Most of these variables are self-explanatory—see Table 6-2 for the details. Table 6-2. Server Configurations

Environment Variable

Contents

browserFileNames

A comma-separated list of the full paths to the executables of the browsers you want to test.

url

The URL to the test runner, including the appropriate query string to autorun the appropriate test suite.

port

The port the JsUnit Server is running on; omitting this variable results in port 8080 being used.

resourceBase

Defines the document root of the JsUnit Server. A blank value (the typical setting) results in the jsunit installation directory.

logsdirectory

The directory where the results of running tests will be written. A blank value defaults to jsunit/logs.

remoteMachineURLs

A comma-separated list of the URLs of any remote machines on which you want to run tests. These remote machines require a configured installation of the JsUnit Server.

Once you’re configured for the test suite (or test page, for that matter) and browser combinations, you simply run the standalone_test target. In the NetBeans development environment, this will look like Figure 6-25.

189