Testing Web services and RIAs

The component nature of Web services and RIAs can lead to testing headaches. This tip shows how Firefox, Apache and soapUI testing tools can be brought into the QA process.

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.

Testing SOAP clients
One problem with testing SOAP clients generated by toolkits such as Axis2 is that it is hard to see exactly what the client is generating. Furthermore, the error messages can be confusing and sometimes you can't tell if the request ever got to the SOAP service. The solution is a tool such as TCPMON that sits between the client and the network, capturing the complete text of request and response. When testing, you direct your client to a localhost address and TCPMON relays requests to the real Web service while capturing the complete text of both request and response. Once captured, requests can be modified and sent repeatedly.

Although originally created for testing SOAP architectures, TCPMON works with RESTful services as well. The first versions of TCPMON were part of the original Axis project, but now the tool has its own Apache Software Foundation project and Web site. The present version has a spiffy graphic user interface making it easy to use.

There are also other open source and commercial utilities that provide the same or expanded functionality. An example is the widely used soapUI tool available in free and commercial versions. The soapUI tool can import WSDL Web service descriptions and use the information to assist in testing. In addition, soapUI can be integrated with common IDEs such as NetBeans.

Testing with recorded requests
The most useful thing about using TCPMON or similar utility is that once you have the complete text of a Web service request or response it simplifies testing various components. For example, SOAP clients build a request as an XML structure in memory and then serialize it. The time consumed doing this makes it harder to create a realistic Web service load test on a simple network. With the complete request in a text file it can be sent to the server with practically no overhead.

Since the captured request and response messages are editable text, you can test the application's response to badly formatted messages. This enables tests that would be impossible with your normal client software, for example, creating SOAP messages with bad signing certificate data.

References
A Wikipedia article on unit testing.

Examples of using the open-source TCPMON tool.

Home page for the soapUI testing tool.


This was first published in June 2008

Dig deeper on SOA, XML and Web Services Development Tools

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close