Hi Steve, ----- Original Message ----- From: "Molitor, Stephen" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, September 11, 2001 12:22 AM Subject: Unit Testing Actions
> What's the best way to unit test Struts Actions? Create mock objects > (request, session, servlet, etc.)? J2EEUnit, Catctus, HTTP Unit? Which > approach are people having the most success with? > J2EEUnit is the old name of Cactus (http://jakarta.apache.org/commons/cactus). Several persons have successfully used Cactus to unit test Struts Actions. No tutorial is yet available on the Cactus web site (soon to come) for that but you should everything you need in the mailing-list. Have a look at the cactus archives (http://www.mail-archive.com/cactus-user%40jakarta.apache.org/) , searching for "struts". > Also, Craig M. mentioned a while back about a unit testing framework for > Struts itself. How is that coming along? Just curious. > I guess that Craig meant Cactus when he was referring to the unit testing framework. There are some tests already implemented using Cactus within Struts but there is a lot to do. I know David Winterfeldt was working on the subject at some point. I am myself 100% busy improving Cactus but there is a identified task within Cactus to provide as much helper classes as possible to help unit test Struts Actions. However, it is already quite easy to unit test a struts action. Here is an example of a test for a MyAction class that extebds the Strust Action class : public void beginXXX(WebRequest theRequest) { // set up any needed HTTP parameters (cookies, HTTP params // in the request, headers, ...). For example: theRequest.addParameter("param1", "value1"); [...] } public void testXXX() { MyAction action = new MyAction(); action.setServlet((new ActionServlet(config)).init()); // Test any method of the action class (including the perform() method) action.myMethod(request, response, config, action, [..]); // Do JUnit asserts } public void endXXX(WebResponse theResponse) { // perform any needed asserts on the output stream // or returned cookies, HTTP headers assertEquals("value", theResponse.getCookie("someCookie")); [...] } > Thanks! > > Steve Molitor > [EMAIL PROTECTED] > thanks -Vincent
