Testing Web services and RIAs
Given the number of components that go into a complete Web service, it is not surprising that complete testing is difficult. Just consider how many different technologies may be involved in even a simple client and server. An Ajax style rich Internet application (RIA), for example, combines JavaScript, CSS and HTML markup on the client alone. Add in the Internet connection, plus the service side application code and the database it works with and you have many points of potential conflict, bugs and performance problems.
General testing principles
Let's review some of the general principles of testing and debugging, which are applicable no matter which toolkits or languages you use:
Design with testing in mind. A proper choice of abstraction for inputs and outputs will allow testing without the added complexity of a network or a HTTP server.
Test separate parts wherever possible. Some developers favor the "unit testing" philosophy to enforce testing at a low level. In any case, use language features such as assertions in Java to catch and identify bad inputs to functions.
Document as you go, use explanatory names for interfaces, classes, methods and variables. One of the advantages claimed for unit testing is that it forces good documentation.
Testing browser clients - Firefox
We have come a long way from the days when a browser's "view source" command was the only way to inspect a Web page. These days a typical RIA uses HTML markup, CSS driven formatting and JavaScript with a Web service providing data in JSON (JavaScript Object Notation) or XML. Fortunately developer support tool providers are working to keep up.
The most advanced support tools today are found in the free open-source Mozilla Firefox browser, a program that belongs on every serious Web developer's hard disk. I just installed Firefox 3.0 and was delighted to find that the "Live HTTP Headers" tool is now part of the standard download. This tool can capture and display the exact request and response headers for all HTTP requests that go to make up a modern Web page. Inspecting these headers to ensure that the parts of your RIA are being requested correctly is a really good idea.
There are a number of Firefox add-ons for dealing with JavaScript, which is a good thing since JavaScript is an essential part of typical RIAs. I installed the "Firebug" add-on, which has been updated for Firefox 3.0. The interface provides for inspecting and editing HTML, CSS, and JavaScript. The inspector for HTML is based on the document object model (DOM), so complex pages can be examined.
With Firebug network monitoring enabled, you can capture the request and response headers and see the response size and amount of time each request required. This feature is great for seeing the causes of your application's perceived response speed. You may be surprised to find that a single request resulting in an error is holding up the entire application.
The Firebug JavaScript inspector can monitor the execution time of all JavaScript functions. You can modify JavaScript objects and insert breakpoints in JavaScript methods as well as change variable values, insert new code or execute JavaScript directly. By executing the JavaScript that requests data from your Web service, you can test with a wide range of inputs without having to create separate HTML pages. In general, Firebug is designed to assist developers with Ajax based applications, using both XML and JSON.
By William Brogden
No comments:
Post a Comment