Java Reference
In-Depth Information
E
<scriptdef name="JSLintant" src="${JSLint.src}/JSLintant.js"
language="javascript">
<attribute name="options" />
<attribute name="JSLintpath" />
<element name="fileset" type="fileset" />
</scriptdef>
<target name="run-js-lint">
<JSLintant options="{eqeqeq : true, white: true, plusplus : false,
bitwise : true, evil: true, passfail: false}"
JSLintpath="${JSLint.src}/fullJSLint.js">
<fileset dir="${src.dir}" />
</JSLintant>
</target>
F
</project>
We start our Ant script by defining properties for the locations of directories and files
b
relative to where we run the Ant build. Next, we define a
rhinounit
Ant script
C
and its arguments by loading its source from rhinoUnitAnt.js. We call the script
D
with
a
fileset
pointing to our JavaScript unit test source, where we include all files with the
js extension. In the same way that we defined a script for
rhinounit
and ran our tests,
we define a script for
JSL
int
E
to help us detect scripting issues, and we finish by run-
ning this
JSL
int script
F
on our source directory. For more on
JSL
int, please see sec-
tion 13.6, “Checking best practices with
JSL
int.”
RhinoUnit tip
When you invoke the
rhinounit
Ant script, make sure you point the
rhino-
UnitUtilPath
argument to the location of the rhinoUnitUtil.js file, for example:
rhinoUnitUtilPath="${rhinounit.src}/rhinoUnitUtil.js"
This takes care of JavaScript unit testing in the build file; please consult the Rhino-
Unit
14
website for additional documentation. Next, we look at the alternative to
RhinoUnit and browser emulation with JsUnit, a framework that drives a web browser
á la Selenium.
13.4.2
JavaScript testing with JsUnit
JsUnit
15
is a JavaScript unit-testing framework written in JavaScript and in Java. We use
it from Ant to drive a web browser in order to validate the same JavaScript we just
tested in the previous section. JsUnit is similar to Selenium in that it controls a web
browser and the tests run in that browser's JavaScript engine.
14
RhinoUnit:
http://code.google.com/p/rhinounit/
15