dcsimg
Servlets
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Matt_Connors
Posted On:   Tuesday, May 14, 2002 07:28 AM

I'm doing web development using Java/JSP. Most of our applications use a Model 2 (MVC) architecture. Does anyone have experience, or insight, on how to best incorporate JUnit into such an environment? Is it possible to use JUnit to test the servlet itself?



An even more general question is how do I use JUnit to test classes that extend other classes since Java does not suppport multiple inheritance?



Thanks,

Matt

Re: Servlets

Posted By:   Alex_Orischenko  
Posted On:   Tuesday, August 6, 2002 07:59 AM

j2eeUnit (Cactus) is solution for your problem. This is extension of JUnit for serverside applications.

Re: Servlets

Posted By:   Anonymous  
Posted On:   Wednesday, June 12, 2002 03:32 AM

Matt,

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...


Regards,

Robert.

Re: Servlets

Posted By:   Anonymous  
Posted On:   Tuesday, May 14, 2002 11:30 PM

Take a look at http://c2.com/cgi/wiki?ServletTesting

Regarding your second question - I don't really understand your doubt. What would you do if multiple inheritance were possible?

About | Sitemap | Contact