aspose file tools*
The moose likes Testing and the fly likes TestCase with Apache Jakarta Cactus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "TestCase with Apache Jakarta Cactus" Watch "TestCase with Apache Jakarta Cactus" New topic
Author

TestCase with Apache Jakarta Cactus

Ravi Verma
Ranch Hand

Joined: Aug 30, 2001
Posts: 42
Hi All,
I actually wanted to know how to write TestCases for Normal Java Classes(not servlets,jsp,ejb) using jakarta Cactus Framework. Thanks in advance. Your response is grately appreciated.


Ravi
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Ravi,
We don't have many rules at Javaranch, but our naming policy is one of them. Please read this policy and change your display name to comply with it if you wish to continue posting. Thanks.
You can change your display name here.


Matthew Phillips
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Ravi:
I actually wanted to know how to write TestCases for Normal Java Classes(not servlets,jsp,ejb) using jakarta Cactus Framework. Thanks in advance. Your response is grately appreciated.

Cactus is used just for testing server-side stuff -- JSPs, Servlets, EJBs etc.
Check out JUnit. It's a framework that's used to test "normal" java classes.
Vinay Thomas
Greenhorn

Joined: Jan 14, 2003
Posts: 5
Hi Ravi,
I'm proposing Cactus at my current client as a unit testing framework for server side objects. During my proof of concept process, I've played around with Cactus quite enough to answer basic questions atleast.
Let me know if you have any specific questions.
FYI - Cactus is usually shipped with examples and that should be a good start to begin with.
Thanks,
Vinay Thomas.
[ January 14, 2003: Message edited by: Vinay Thomas ]
Vinay Thomas
Greenhorn

Joined: Jan 14, 2003
Posts: 5
Ravi,
Sorry for mis-interpretation of your question.
Cactus uses JUnit as part of its framework. If you checkout the base class of ServletTestCase, you will see junit.framewor.TestCase. Which means, you can right away create a new test case extending directly from TestCase instead of ServletTestCase/JspTestCase/FilterTestCase to do your 'non-serverside java classes'.
Hope it helps.
[ January 14, 2003: Message edited by: Vinay Thomas ]
Ravi Verma
Ranch Hand

Joined: Aug 30, 2001
Posts: 42
Hi Vinay,
I appreciate for your response. You know now i am able to write testcases for Servlets,JSP with Cactus framework but i cannot write testcases properly for normal java classes(other than jsp,servlets,ejb). I used AbstractTestcase to develop the testcases for normal java classes. But it is working in wierd manner rest of the testcases are working fine. If u had chance to having good experience on this pls write reply back to me.
-Ravi
Vinay Thomas
Greenhorn

Joined: Jan 14, 2003
Posts: 5
I'm speculating your AbstractTestCase usage. It is an abstract class and it expects you to provide implementation for runTest() method. Also it is used as a base class for the Cactus framework for server side unit testing.
If you extend your class directly from junit.framework.TestCase and implement your testXXX() methods, it should work fine.
Help me to help you answer your questions - Have you used JUnit before?
Here is the javadoc comment from Cactus for AbstractTestCase class: Abstract class that is a thin layer on top of JUnit and that knows about test cases that are executed on the server side. This class is independent of the protocol used to communicate from the Cactus client side and the Cactus server side; it can be HTTP, JMS, etc. Subclasses will define additional behaviour that depends on the protocol.
[ January 14, 2003: Message edited by: Vinay Thomas ]
Ravi Verma
Ranch Hand

Joined: Aug 30, 2001
Posts: 42
Hi Vinay,
I completely agree what you said, basically i tried writing testcase with AbstractTest as it is extensiontion to junit.framework.TestCase and i implemented runTest() method also but the behaviour is weird for this. Its like each Testcase is executed 'n' times for 'n' number number of times. Actually each testcase(testXXX()) should execute only once. But its happening for me for that reason i posted the query here.
Here is the sample java file
**************************************************
import junit.framework.*;
import org.apache.cactus.AbstractTestCase;
public class TestHBean extends AbstractTestCase
{
HBean _hcb;
public static void main(String args[]) {
junit.textui.TestRunner.run( suite() );
}
// loading the class
public static Test suite() {
return new TestSuite( TestHCFSBean.class );
}
public TestHBean(String name){
super(name);
}
public void runTest(){
try{
_hcb = new HBean();
testgetOrderNumber();
testgetFulfillmetSetNumber();
testgetEquipmentAreaName();
}catch(Exception e){e.printStackTrace();}

}
public void testgetOrderNumber(){
_hcb.setOrderNumber(2000006);
assertEquals(2000006,_hcb.getOrderNumber());
}
public void testgetFulfillmetSetNumber(){
_hcb.setFulfillmetSetNumber(200);
assertEquals(200,_hcb.getfulfillmentSetNumber());
}
public void testgetEquipmentAreaName(){
_hcb.setEquipmentAreaName("AREAName");
assertEquals("AREAName",_hcb.getEquipmentAreaName());
}
}
*************************************************
Pls help me in this regard
-Ravi
[ January 14, 2003: Message edited by: Ravi Kumar ]
Vinay Thomas
Greenhorn

Joined: Jan 14, 2003
Posts: 5
Ravi,
As I was indicating you before, if you use AbstractTestCase for testing normal java classes you would see 'n' results 'n' times for a very simple reason. Cactus framework invokes runTest()() method for every test method to be executed. Since you have added all test methods as part of your runTest() method, they all are getting executed every time Cactus framework executes testmethod. Hence you see 'n' results 'n' times.
So, you should extend your test case class directly form junit.framework.TestCase but not org.apache.cactus.AbstractTestCase.
Hope you got that right .
[ January 14, 2003: Message edited by: Vinay Thomas ]
Ravi Verma
Ranch Hand

Joined: Aug 30, 2001
Posts: 42
Oh this is cool!! I got it now. Thanks for your info but to write testcase using junit.framework.TestCase i should use normal Junit Framework rather than Cactus.
Edward Valdemar
Greenhorn

Joined: Jun 12, 2003
Posts: 2
Originally posted by Ravi Kumar:
Hi Vinay,
I completely agree what you said, basically i tried writing testcase with AbstractTest as it is extensiontion to junit.framework.TestCase and i implemented runTest() method also but the behaviour is weird for this. Its like each Testcase is executed 'n' times for 'n' number number of times. Actually each testcase(testXXX()) should execute only once. But its happening for me for that reason i posted the query here.
Here is the sample java file
**************************************************
import junit.framework.*;
import org.apache.cactus.AbstractTestCase;
public class TestHBean extends AbstractTestCase
{
HBean _hcb;
public static void main(String args[]) {
junit.textui.TestRunner.run( suite() );
}
// loading the class
public static Test suite() {
return new TestSuite( TestHCFSBean.class );
}
public TestHBean(String name){
super(name);
}
public void runTest(){
try{
_hcb = new HBean();
testgetOrderNumber();
testgetFulfillmetSetNumber();
testgetEquipmentAreaName();
}catch(Exception e){e.printStackTrace();}

}
public void testgetOrderNumber(){
_hcb.setOrderNumber(2000006);
assertEquals(2000006,_hcb.getOrderNumber());
}
public void testgetFulfillmetSetNumber(){
_hcb.setFulfillmetSetNumber(200);
assertEquals(200,_hcb.getfulfillmentSetNumber());
}
public void testgetEquipmentAreaName(){
_hcb.setEquipmentAreaName("AREAName");
assertEquals("AREAName",_hcb.getEquipmentAreaName());
}
}
*************************************************
Pls help me in this regard
-Ravi
[ January 14, 2003: Message edited by: Ravi Kumar ]

Ravi,
Could you e-mail me or post what your _hcb method looks like?


Thanks,<br />Edward
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TestCase with Apache Jakarta Cactus