Divided our testing strategies along similar patterns.
Use functional tests for the whole application stack as it appears to a user by driving and testing the application with HtmlUnit and Selenium.
Isolate JavaScript into libraries and tested those independently with RhinoUnit and JsUnit.
Validate server-side XML and JSON services using Apache Commons HttpClient, jslint, and jslint4java.
Testing Ajax from below three aspects as it's asynchronous
1. Testing client-side scripts
1) use RhinoUnit
2) use JsUnit
The major difference between the two is that RhinoUnit emulates a web browser while JsUnit drives a real web browser process. When using JsUnit, the browser itself provides JavaScript support. In RhinoUnit, Java 6 or Apache BSF plus Mozilla Rhino engine provides JavaScript support.
The RhinoUnit pros are that it is a 100% Java solution and is easy to integrate in a build process.
The JsUnit pros are that it drives native browsers, and can manage a farm of JsUnit test servers.
Use RhinoUnit when...
your application is independent of operating system features and browser specific implementations of JavaScript, DOM, CSS, etc.
Use JsUnit when...
when you require validation of specific browsers and operating systems, especially if the application takes advantage of or depends on a browser's specific implementation of JavaScript, DOM, CSS, etc.
2. Testing server services
Testing with HttpClient
The idea behind testing the application services layer separately is to validate each service independently form HTML, JavaScript, DOM, and how the application uses the data.
An application calls a service from JavaScript through the XMLHttpRequest object.
3. Functional testing
1) Testing usingHtmlUnit
2) Testing usingSelenium
The art of testing Ajax with Selenium is about embedding JavaScript in your JUnit code.
This can be confusing since you are embedding JavaScript in Java, but it is what is required since the Selenium server
controlling the web browser will run the JavaScript for you.
Testing Google Web Toolkit applications
The Google Web Toolkit (GWT) is a free open source framework used to create JavaScript front-ends to web applications. GWT application development has a twist though: you write your applications in Java. To this end, Google provides the Google Plugin for Eclipse, you develop and test in Java and, when 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 model, where you application is translated to JavaScript and then is run in a browser.
It is important to understand that GWTTestCase does not 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.
You can think of GWT tests as integration tests. The tests cannot rely on any user interface element driving the application.