Java Reference
In-Depth Information
13.1.3
A brave new world
This interaction is quite different from the web-classic architecture where a page is
loaded, a user interacts with the page causing another page to load, and then the cycle
repeats. With Ajax, the page is loaded once, and everything happens within that page.
JavaScript code runs in the page to perform I/O with the server and updates the in-
memory DOM of the page, which the browser displays to the user.
13.1.4
Testing challenges
The challenge in writing tests for the application interaction described previously is
the asynchronous aspect of HTTP communications and the DOM manipulation by
JavaScript code. The difficulty is how to drive a self-changing application when those
changes are asynchronous to the test itself.
In addition to testing the traditional page state described in chapter 12, you should
also test an Ajax application's best practices. Tests should exercise features 4 like drag
and drop, form validation and submission, event handling, back button, refresh but-
ton, undo and redo commands, fancy navigation, state management and caching, and
user friendliness (latency, showing progress, timing out, and multiple clicks).
Further complicating matters, different implementations of Ajax component tech-
nologies like JavaScript, DOM , and XMLH ttpRequest exist in different browsers from
different vendors. Although various free and open source libraries abstract these dif-
ferences away, an application is nonetheless more complicated to test. You may want
to ensure test coverage for all code paths for all supported browsers on all supported
operating systems.
Next, we split up testing this complex application stack into more manageable tiers
through functional testing, testing client-side scripts, and testing server services.
13.2
Testing patterns for Ajax
Before we jump into test code, we survey the testing patterns we use to verify the vari-
ous aspects of an Ajax application. We can orchestrate testing with three types of tests:
Functional testing drives the whole application from the client-browser and
usually ends up exercising all application layers.
Client-side script unit testing covers the JavaScript scripts running in the
browser. The application page hosting the script isn't tested.
Service testing verifies services provided by the server and accessed from
JavaScript XHR objects.
Let's look at these types of tests in more detail before we turn to implementation.
13.2.1
Functional testing
Functional testing drives the whole application from the client browser and usually
ends up exercising all application layers. As we discussed in chapter 12, a functional
4
See Ajax in Action : http://www.manning.com/crane/.
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search