Java Reference
In-Depth Information
You can run a self-test on JsUnit itself by running the test suite jsunit/tests/jsUnitTest-
Suite.html
.
The result will show you the green bar with 90 successful tests.
JsUnit tip: Status
Aborted
or tests time out
JsUnit doesn't give you much feedback when something goes wrong. If you see
Aborted
in the JsUnit Status field, check your paths starting with
link
href
and
script
src
and then
addTestPage
.
Now that we have a manual way to run tests, let's move on to automating tests with Ant.
13.4.6
Running JsUnit tests with Ant
JsUnit includes the file jsunit/build.xml, which you can use as a template to call JsUnit
tests from Ant. The Ant build file will manage web browsers, invoke tests, and cre-
ate reports.
JsUnit tip: Java 6 runtime requirement
The version of JsUnit tested here, version 2.2, will run only with Java 6 or greater.
If you use an earlier version of Java you will see the error
java.lang.Unsupported-
ClassVersionError:
Bad
version
number
in
.class
file
.
Listing 13.8 shows the build.xml file that excerpts invoke our test suite.
Listing 13.8
JsUnit build.xml excerpts
<?xml version="1.0" encoding="utf-8"?>
<project name="JsUnit" default="standalone_test" basedir=".">
<property name="
jsunit.dir
" value="
jsunit
"/>
B
C
<property name="
browserFileNames
"
value="
c:\program files\internet explorer\iexplore.exe
"/>
D
E
<property id="
logsDirectory
" name="
logsDirectory
" value="
logs
"/>
<property id="
timeoutSeconds
" name="
timeoutSeconds
" value="
60
"/>
F
<property id="
url
" name="
url
"
value="
http://localhost:8080/jsunit/jsunit/testRunner.html?testPage=http://
localhost:8080/jsunit/src/test/webapp/jsUnitTestSuite.html
"/>
<property name="bin" location="${jsunit.dir}/java/bin"/>
<property name="lib" location="${jsunit.dir}/java/lib"/>
<property name="loggingPropertiesFile" location="logging.properties"/>
<path id="classpath">
<fileset dir="${lib}">
<include name="*.jar"/>
<include name="*/*.jar"/>
</fileset>
G