Establishing an Infrastructure for Immediate Servlet Testing

[article]
Summary:

If you establish an appropriate infrastructure, you can perform client-side testing on a servlet immediately after you compile it and perform unit testing. Of course, testing early doesn't eliminate the need for later application-wide testing. However, it does improve the overall efficiency of your development process and make the later phases of testing decidedly less painful.

Testing a servlet via an HTTP connection (client-side testing) is an important part of servlet testing. However, I have seen some groups delay this testing until a fair amount of development had been completed because they thought that the servlets first needed to be deployed to a common server. This is an inefficient practice that hampers productivity. If you delay your testing until later in the development process, you might reuse problematic code and build on it before you realize that you have a problem. If so, a simple one-minute, one-line change can blossom into an extensive debugging and/or rewriting nightmare.

If you establish an appropriate infrastructure, you can perform client-side testing on a servlet immediately after you compile it and perform unit testing. First, make sure each developer has access to an individual Web server running on his or her machine. Next, configure your build process so that you can run your servlets immediately after compilation, with no extra steps. To do this, implement an efficient way to move .class files as soon as they have been compiled. One way to streamline this process is to configure your build process to place newly built class files into the directories from which your servlet engine runs them; another way is to configure your servlet engine to look into your development directory. You can further speed up the testing process by configuring your servlet engine to recognize updates and execute the current code automatically.

If an application has dependencies on other components (for instance, databases), arrange your environment appropriately by sharing a common database, having personal databases, or stubbing out database access.

Of course, testing early doesn't eliminate the need for later application-wide testing. However, it does improve the overall efficiency of your development process and make the later phases of testing decidedly less painful. 

This article derives from the concepts developed in the book "Bulletproofing Web Applications (With CD-ROM)" by Adam Kolawa, Wendell Hicken, and Cynthia Dunlop-published November 2001 by Hungry Minds, Inc.

About the author

CMCrossroads is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.