Chapter 7. Cactus
Introduction
Cactus, available from http://jakarta.apache.org/cactus, is an open source unit-testing framework for server side Java code. Specifically, Cactus allows you to test servlets, JSPs, and servlet filters.[31]
Cactus extends JUnit to provide three specific
junit.framework.TestCase subclasses:
org.apache.cactus.ServletTestCase org.apache.cactus.JspTestCase org.apache.cactus.FilterTestCase
Each Cactus test case provides a specific function and is discussed in more detail in the following recipes. Cactus tests execute on both client and server. This is a significant departure from other testing frameworks and deserves some explanation. When using Cactus, you create a single subclass of one of the previously mentioned classes. Cactus then creates and runs two instances of your test case. One instance runs on the client JVM and the other runs inside of the servlet container’s JVM. The client side allows HTTP headers and HTTP parameters to be added to the outgoing request. The server side invokes your servlet’s methods, performs any necessary assertions, and sends back a response to the client. The client may then assert that the response contained the expected information.
Tip
It is important to know that you have to deploy your Cactus tests to
the server. Specifically, you must create a web-application
WAR file containing a valid
web.xml file, all Cactus tests, and all support classes needed for your tests to execute. This is necessary because Cactus tests are ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access