Server-side Java testing with Cactus

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.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值