Cactus is an open-source framework for in-container testing server-side Java code (mostly J2EE components in the current version of Cactus). It is an extension of JUnit that was created by Vincent Massol in 1998.
How Cactus works
Stepping through a test
for each test (testXXX methods in the YYYTestCase classes),
1. execute beginXXX
if there is a beginXXX method, cactus executes it. The beginXXX method lets you pass information to the redirector.
2. open the redirector connection
The YYYTestCase opens a connection to its redirector.
3. create the server-side TestCase instance
The redirector creates an instance of the YYYTestCase class. Note that this is the second instance created by Cactus, the first one has been created on the client side (by the JUnit TestRunner). Then, the redirector retrieves container objects and assigns them in the YYYTestCase instance by setting class variables.
4. call setUp, testXXX, and tearDown on the server
The redirector calls the JUnit setUp method of YYYTestCase, if there is one, then it calls the testXXX method. The testXXX method calls the class/methods under test, and finally the redirector calls the JUnit tearDown method of the TestCase, if there is one.
5. execute endXXX
Once the client side has received the response from its connection to the redirector, it calls an endXXX method (if it exists). This method is used so that your tests can assert additional results from the code under test.
i.e:
public void endXXX (WebResponse response) {
assertEquals("value", response.getCookie("cookiename").getValue());
...
}
6. Gathering the test result
in step 3, the redirector saves the test result in a variable stored with the ServletConfig object. The Cactus client side now needs to retrieve the test result and tell the JUnit test runner whether the test was successful, so the result can be displayed in the test runner GUI or console. To do this, the YYYTestCase opens a second connection to the redirector and asks it for the test result.