This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cactus vs StrutsTestCase

 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your informative responses. I am evaluating both and find StrutsTestCase mock approach close to meet our requirements so far.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic