• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TestCase with Apache Jakarta Cactus

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic