GeeCON Prague 2014*
The moose likes Testing and the fly likes Cactus vs StrutsTestCase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Testing
Bookmark "Cactus vs StrutsTestCase" Watch "Cactus vs StrutsTestCase" New topic
Author

Cactus vs StrutsTestCase

Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

I am joining a new project within two weeks that is going to use Struts, Hibernate, XDoclets, Ant etc. together in a Debian O/S plus Oracle backend. For that project we found that there are two primary testing strategies used in server-side testing: mock object (MO) and in-container (IC). I got a look of what is what but would like to know which approach is generally usedmore?
We also found two open source projects are popular for this testing - Apache Cactus and StrutsTestCase. Now which one should fit better testing Struts applications?
Any comment or lights please? :roll:


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Personally, I don't like either solution. My perference is to not unit test Struts Actions at all. Generally, it is a good idea to keep as much business logic out of the Struts Actions as possible. If you achieve this goal then there is actually very little in the Actions that need to be tested, mainly routing logic, and this should be covered by funtionality tests... not unit tests.
The business logic that the Struts Actions use, can and should be unit tested. These classes, if designed properly, will be decoupled from Struts and the Servlet API. This removes the need for in-Container testing entirely.
Constructing applications in this fashion will make unit testing easier, faster, and more reliable. Furthermore, this will also lead to a more flexible and maintainable application.
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
I haven't been all that thrilled with Cactus either, although I will say I've gotten a lot of benefit out of StrutsTestCase.
Maybe its because I've worked on web apps with very rich DHTML that required a lot of different kinds of data to be prepared by the action, and complex data-dependent routing between the actions. DHTML is almost impossible to create automated tests for because the javascripted behaviour makes testing the HTML useless. I need to be sure that at least the data bindings and forwardings are correct.
STC is very good for writing tests like "I expected something to have been bound to request attribute 'X', was it?" or "If form parameter 'foo' wasn't provided validation should have complained... did it?". Also, running a STC test is a heck of a lot faster than building the entire app and re-deploying it, particularly if you use mocks for the connection between the action and a back-end ejb layer. Since Struts won't let you dynamically re-load configuration files, continually starting and stopping Tomcat can be a pain in the backside. STC can be less of a hassle.
[ January 17, 2004: Message edited by: Reid M. Pinchback ]

Reid - SCJP2 (April 2002)
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I, too, would put as much business logic as possible (that is, all of it ) into POJOs - it makes testing *and reusing* the logic just so much easier...
I would also want to write acceptance tests (currently I actually think that they are even more important than unit tests). My framework of choice would be Fit/FitNesse ( http://fitnesse.org/ ).
If you still find yourself wanting to write unit tests for Struts classes itself (and you might), I would prefer mocks over in-container testing - it's easier and provides faster feedback. Of course, in-container testing actually might point out some problems mocking will not, so I could imagine doing a mix of all the approaches. But I would delay writing in-container tests as long as possible.
Just my 0.02 ...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Thank you very much for your informative responses. I am evaluating both and find StrutsTestCase mock approach close to meet our requirements so far.
 
GeeCON Prague 2014
 
subject: Cactus vs StrutsTestCase