Wednesday, June 12, 2002 03:32 AM
since you mention MVC you are probably developing your apps with the Struts framework, right?
If yes, then you can get quite far with so-called mock testing, i.e. create mock versions of all classes that are used in the calls to your action classes by Struts, most probably you will need things like MockServletRequest, MockSession etc.
Your test cases can then simply instantiate your action classes, prepare the correct mock objects (most notably, put all necessary attributes in MockServletRequest & MockSession instances) and call the perform() method passing your mock instances as parameters.
We do this type of testing a lot. Previously, we used HttpUnit to fake a real HTTP client and interact with the Servlet via HTTP. This was far too complicated in our complex environment.
Now, with our mock testing framework combined with Struts' MVC approach, we can test our Action classes just like any other stupid class.
This whole approach has easened up our testing so much that we can now better follow the principle "code a little, test a little,..." although we are developing a web application.
Yes, by using this approach we of course miss a lot of tests that eg. verify correctly placed HTML controls on our application UI pages. We leave some testing to the humans...