You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Vincent Massol <vm...@octo.com> on 2001/04/30 23:07:40 UTC

Re: [cactus] Unit Testing Action Handlers in the Struts Framework.

----- Original Message -----
From: "Natra, Uday" <UN...@cooksys.com>
To: <ja...@jakarta.apache.org>
Sent: Monday, April 30, 2001 9:08 PM
Subject: Unit Testing Action Handlers in the Struts Framework.


> Hi All,
> I am using Struts as the FrameWork for my J2EE application and I am
looking
> at Cactus as a viable option for unit testing my action handlers. But I am
> not sure about how I can do that. Because the struts frame work does a lot
> of ground work before it invokes the Perform method of the Action Handler,
I
> am not sure on how to procees with the Unit Testing of the Action
Handlers.
> If some one throw some light on this Issue, it will be really helpful for
> me. Thanks in Advance for Ur time.
>

Hi,

At the current time Cactus should be used for unit testing (and not
functional testing - although there are plans to add functional testing
later). This means that if you want to unit test the perform method of one
of your Action, you only need to be concerned by the input and output of
this method.

Let's take a closer look at the perform method :

public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)

So, before calling your perform method you need to initialize the needed
objects with values consistent with the test you want to do. Request and
Response are handled directly by Cactus. Look at the Cactus tutorial for how
to initialize them with correct values.

The challenge is with initializing ActionForm and ActionMapping. This
requires a bit more work because you have to initialize them by hand. Struts
being well written, all the methods have getters and setters so it is quite
easy to do that. But you still have to do this tedious work ... (this is the
price to pay if you want to be able to finely choose your method input
values, or in other words, if you want to unit test your method).

A test suite using Cactus is scheduled for Struts. I am sure that when it is
done, we will have more knowledge about it and maybe we could even add some
generic static methods to help initialize some Struts objects. In the
meantime you are a discoverer ... :) If you can contribute to Struts and
Cactus by providing the results of your progress, that would be a great help
! Even discussing it on the jakarta-commons mailing list is a great help.
You might also want to cc the struts mailing list on this subject.

Thanks a lot.

> Uday.
Vincent.