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 Software Engineer, TubeMogul, Emeryville, CA, USA.
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.
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