wood burning stoves 2.0*
The moose likes Testing and the fly likes benefits of cactus? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "benefits of cactus?" Watch "benefits of cactus?" New topic
Author

benefits of cactus?

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30369
    
150

I've read a little about Cactus, but I'm not clear on what it buys you. (And since Vincent is here, I figured it would be a good time to ask!)
I've seen Cactus being described as useful for EJBs, Servlets and taglibs.
EJBs can be tested with pure Junit. You can call the EJB the same way the client does (JNDI lookup) which tests the whole process. You need to have the server running here, but you would need it with Cactus too.
Servlets and taglibs can be tested using Mock Objects without the server running. It seems like the only extra thing Cactus gives you is interaction with the server. But it would already be assumed that the server works, so it would not be necessary to test that.
I feel like I'm missing something. Cactus comes up often, but I don't see the benefit.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
I'm not Vincent, but here's my $0.02:
EJBs can be tested with pure Junit.
You are right, but the problem here is that you're not sure whether your tests are accurate or not. This is because you're running from a completely different environment than where your EJBs are stored. In other words, you are using two JVM, and the idea is to test under the same JVM.
So what cactus provides is a way to run the tests under the same environment as your EJBs are deployed (in the same container.
If you'd like to explore more, have a look a these articles :
http://www7b.boulder.ibm.com/wsdd/techjournal/0206_wosnick/wosnick.html
http://approximity.com/testing/cactus.html


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30369
    
150

Andres,
It still wouldn't be the same environment, at last for us. We do the testing in the IDE (WSAD.) The EJBs are really going to be running on the server in production.
In any event, why does the JVM make a difference. Can't it be assumed that the JVM works as expected. If it doesn't, you'd have much bigger problems.
Sorry if I'm being dense, but I really don't see the importance of this.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561

It still wouldn't be the same environment, at last for us. We do the testing in the IDE (WSAD.) The EJBs are really going to be running on the server in production.
In any event, why does the JVM make a difference. Can't it be assumed that the JVM works as expected. If it doesn't, you'd have much bigger problems.

from the link I posted:
It is necessary to test from within the application server container for accurate test results. This is the case because no matter how good a test environment is, a server-side component is likely to run slightly differently in production mode (that is, in the real, production-level run-time environment). This could be due to a large number of factors, for example, the specific Java JVM used at run time, the other components interacting in unpredictable ways, the stress or load on the component, or the component logic using differing code paths. When you use the EJB Test Client, you are testing your code in the container in which it is running. If anything undesirable happens, you will notice it. The same can be said about Cactus at a simpler level.
Vincent Massol
Author
Ranch Hand

Joined: Aug 09, 2003
Posts: 70
Originally posted by Jeanne Boyarsky:
I've read a little about Cactus, but I'm not clear on what it buys you. (And since Vincent is here, I figured it would be a good time to ask!)
I've seen Cactus being described as useful for EJBs, Servlets and taglibs.
EJBs can be tested with pure Junit. You can call the EJB the same way the client does (JNDI lookup) which tests the whole process. You need to have the server running here, but you would need it with Cactus too.
Servlets and taglibs can be tested using Mock Objects without the server running. It seems like the only extra thing Cactus gives you is interaction with the server. But it would already be assumed that the server works, so it would not be necessary to test that.
I feel like I'm missing something. Cactus comes up often, but I don't see the benefit.

For EJBs, see http://jakarta.apache.org/cactus/writing/howto_ejb.html
Also, you may want to test your EJBs but not the database access. In that case, with Cactus you can still test the interactions with the container and then use mock objects to prevent the calls to go through the database, etc.
Generally speaking, Cactus is useful to get a really good confidence that your code will run fine when deployed. It also helps you practice deployment (which is not an easy thing to do) from day one.
Writing a Cactus test to unit test a servlet/taglib/jsp/etc is much easier than using mock objects. I personally write 80% of my "unit" tests using mock objects and 20% using Cactus (especially when I'm coding web applications). The rest is functional tests.
See http://jakarta.apache.org/cactus/mock_vs_cactus.html for some old comparison I made between Cactus vs Mock Objects. Some of the points are still valid.


-Vincent<br /><a href="http://www.manning.com/massol" target="_blank" rel="nofollow">JUnit in Action</a> author
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30369
    
150

Andres,
Ok. I understand what you are saying now. I'm not sure that I'm convinced it's worth it, but at least I understand.
Vincent,
Thanks for the links. Combining Cactus and mock objects is an interesting idea. You are right about practicing the deployment process. I guess I don't really think about that because in our environment (WSAD), the EJBs get deployed every time you start the server.
It's good to know that Cactus is in addition to and not instead of Mock Objects. I think that's what I was having trouble with.
Are you saying that Cactus serves the same purpose as HttpUnit/JWebUnit for the servlet/taglib/jsp part?
Writing a Cactus test to unit test a servlet/taglib/jsp/etc is much easier than using mock objects. I personally write 80% of my "unit" tests using mock objects and 20% using Cactus (especially when I'm coding web applications). The rest is functional tests.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: benefits of cactus?