Java Reference
In-Depth Information
to support the underlying
JSLint
options. The test calls the
lint
method by specify-
ing two arguments: a
String
describing the source location and another
String
for
the JavaScript code to check, in this case, a
JSON
document
C
. The test uses the
lint
results to create a message
String
D
used in the
Assert
call. If there's a problem, the
test provides the
assertEquals
call
E
with a full description of all issues
JSL
int found.
You'll notice that jslint4java is always behind
JSL
int in terms of features and fixes.
This is because jslint4java embeds
JSL
int (full
JSL
int.js) in its
JAR
file. If you need to use
a newer or different version of
JSL
int in jslint4java, you'll need to download jslint4java,
drop in the version of
JSL
int (full
JSL
int.js) you need on top of the existing one, and
rebuild jslint4java.
In this section, you've seen how to validate server-side services that participate in
an Ajax application independently of the pages and code using them. We've used
Apache Commons HttpClient as our
HTTP
communication library, Java's
XML
API
s,
and
JSL
int through jslint4java. We've separated our tests along the boundary of the
Ajax architecture.
We've now tested the full Ajax application stack. Let's now consider a different way
to build, run, and test an Ajax application with the Google Web Toolkit.
13.8
Testing Google Web Toolkit applications
The Google Web Toolkit (
GWT
)
25
is a free, open source framework used to create
JavaScript frontends to web applications.
GWT
application development has a twist,
though: you write your applications in Java. To this end, Google provides the Google
Plug-in for Eclipse; you develop and test in Java, and when your application is ready
for deployment,
GWT
translates your Java into JavaScript.
GWT
allows you to run and
test your application in
hosted mode
, which runs in Java, and in
web mode
, where you
application is translated to JavaScript and then is run in a browser.
13.8.1
Choosing a testing framework for a GWT application
GWT
supports
JU
nit with the
GWTTestCase
and
GWTTestSuite
classes, which both
extend the
JU
nit
TestCase
class.
GWT
normally integrates with
JU
nit 3.8.2 and works
with 4.6.
GWT
includes junitCreator, a program used to generate empty
GWT
test cases
for a given
GWT
module. As a bonus,
GWT
can also benchmark your application. Because
Java and JavaScript aren't the same, you should test in both hosted and web modes.
It's important to understand that
GWTTestCase
doesn't account for testing the user
interface of an application. You use
GWTTestCase
to test the asynchronous portions of
the application normally triggered by user actions. This means that you must factor
your application and test cases with this element in mind. You can think of
GWT
tests
as integration tests. The tests can't rely on any user interface element driving the
application. Testing the
GUI
requires using the techniques presented in this and the
previous chapters; you can create functional
GUI
tests with Selenium or HtmlUnit.
25