You want to set up Cactus to test Servlets, JSPs, and Filters.
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.
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.
|
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.
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.
|
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.