[ Team LiB ] Previous Section Next Section

7.2 Configuring Cactus

7.2.1 Problem

You want to set up Cactus to test Servlets, JSPs, and Filters.

7.2.2 Solution

Add junit.jar, cactus.jar, httpclient.jar, commons-logging.jar, log4j.jar, and aspectjrt.jar to the client classpath. Add junit.jar, cactus.jar, commons-logging.jar, and log4j.jar to your web application's WEB-INF/lib directory.

7.2.3 Discussion

A Cactus test suite executes on both client and server, requiring both client and server classpaths to be set properly. Cactus configuration is tricky and almost all Cactus problems are related to classpath issues. This chapter assumes Cactus 1.4.1, which bundles the JAR files listed below.

The JAR files that come bundled with Cactus 1.4 and higher include the version of the tool in the filename. For example, the JUnit JAR file used in Cactus 1.4.1 is junit-3.7.jar, specifying JUnit 3.7 is being used. This chapter does not assume any specific version for JAR files because you are free to use any compatible version of a third party tool.

7.2.3.1 Client-side classpath

junit.jar contains the JUnit framework that Cactus extends from, and is needed to compile and run the Cactus test suite. All Cactus framework test cases, as mentioned in the introduction, extend the org.junit.framework.TestCase class.

cactus.jar contains the Cactus framework, which includes three Cactus test cases (ServletTestCase, JspTestCase, FilterTestCase) that your test classes may extend.

httpclient.jar contains a framework supporting HTTP-based methods such as GET and POST, provides the ability to set cookies, and uses BASIC authentication.

aspectjrt.jar is used by Cactus to perform tasks such as configuration checking and logging when methods begin and end.

commons-logging.jar is the Jakarta Commons Logging facade framework. Cactus uses this framework to allow for different logging frameworks to be plugged in. For example, you may seamlessly use log4j or JDK 1.4 logging. Even if you do not want to use logging, HttpClient needs this JAR file in the classpath.

log4j.jar is an optional JAR file needed if you plan on using log4J to log client-side information during your tests.

httpunit.jar, tidy.jar and xerces.jar are optional JAR files needed if you plan to use HttpUnit in your endXXX( ) methods. HttpUnit provides these three JAR files in its distribution.

cactus.properties is a Java properties file that configures the Cactus testing environment.

7.2.3.2 Server-side classpath

The server-side test is deployed as a web application to your servlet container. This means that your web applications, including cactus tests, are deployed as self-contained WAR files. Cactus executes the testXXX( ) methods inside the servlet container's JVM and requires, at minimum, the JAR files described below, which ultimately go in your web application's WEB-INF/lib directory.

cactus.jar contains the core Cactus framework needed by the server to locate Cactus classes used by your Cactus test.

junit.jar contains the core JUnit framework that Cactus extends from.

aspectjrt.jar is used by Cactus to perform tasks such as configuration checking and logging when methods begin and end.

log4j.jar is an optional JAR file needed if you plan on using log4J to log server side information during your tests.

commons-logging.jar is the Jakarta Commons Logging facade framework.

You may be tempted to put these JAR files in your servlet container's shared library path. We recommend that you include all third party JAR files in your web application's WEB-INF/lib directory. This guarantees that the servlet container will find and load the correct classes. Your servlet container probably has different classloaders for your web applications, and different classloaders for running the core libraries needed by your container. See your servlet container's documentation for more information.

7.2.4 See Also

Recipe 7.3 shows how to create an Ant buildfile to support server-side testing. Recipe 7.4 describes the cactus.properties file. Recipe 7.5 shows how to use Ant to automatically generate the cactus.properties file.

    [ Team LiB ] Previous Section Next Section