Setting Up a Stable Build Environment

Problem

You want to configure your environment to support test-first development with Cactus, Tomcat, and Ant.

Solution

Create an Ant buildfile to automatically build, start Tomcat, deploy to the server, execute your web application’s test suite, and stop Tomcat.

Discussion

Setting up an Ant buildfile to properly handle Cactus tests is nontrivial and deserves some explanation A successful environment allows developers to make and test small code changes quickly, and requires a server that supports hot deploying. The ability to hot deploy a modified web application is critical for test-first development because it takes too long to restart most servers. Tomcat provides a built-in web application called manager that supports hot deploying. For more information on Tomcat see Chapter 10.

Figure 7-2 shows a graphical view of the Ant buildfile we are creating. Setting up a stable and easy-to-use environment is imperative for server-side testing. For example, typing ant cactus prepares the development environment, compiles all out-of-date files, creates a new WAR file, starts Tomcat (if it isn’t already started), removes the old web application (if it exists), deploys the updated web application, and invokes the Cactus test suite. The developer does not have to worry about whether the server is started. Ant takes care of the details, allowing developers to concentrate on writing testable code. If the tests are too hard to execute, then developers will ...

Get Java Extreme Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.