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.