I've never used StrutsTestCase before but here's my unit test setup method:
 
    public void setUp() throws Exception {
        super.setUp();
        
        setContextDirectory(new File("C:/Projects/Main"));
        
        //explicitly define the path to web.xml
        setServletConfigFile("C:/Projects/Main/conf/web.xml");
        
        //explicitly define the path to the struts-config for the module being 
tested
        setConfigFile("C:/Projects/Main/conf/action-servlet.xml");
        setConfigFile("C:/Projects/Main/conf/struts-config.xml");
        setConfigFile("C:/Projects/Main/conf/tiles-defs.xml");
    }
 
 
And in my actually test I have:
 
public void testSavePerson() {
     log.debug(".......running testSavePerson()");
     setRequestPathInfo("/Person");
        addRequestParameter("action","create");
        actionPerform();
        verifyForward("create");
        verifyForwardPath("/tiles/PersonEdit.jsp");
        verifyNoActionErrors();
    }
 
Is that what you mean by initializing  struts? Thanks for your reply.
 
-Joe

________________________________

From: Christopher Schultz [mailto:[EMAIL PROTECTED]
Sent: Fri 6/22/2007 11:11 AM
To: Struts Users Mailing List
Subject: Re: Advice on unit testing struts action classes



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joe,

Joe Yuen wrote:
> Can anyone give me any advice on a good tool to use for unit testing
> struts action classes. I am currently using struts 1.2.9 with spring
> 1.2.9 and hibernate. I have looked into StrutsTestCase but cannot get it
> to work. I get the following error:

[snip]

>     [junit] received error 404 : Invalid path was requested

Are you initializing Struts before you attempt to call Action.execute?
Or, are you just doing "new MyAction().execute(...)" ?

If you don't initialize Struts, your unit tests will never work.

Struts 2 has what appears to be a much more flexible action
architecture, which makes unit testing much easier. If you are near the
beginning of your development cycle, you should consider upgrading in
order to facilitate your unit testing.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGfBDl9CaO5/Lv0PARAhBFAKDCLWEJs5LpQSbHn+P3WMvgl0ZeegCfTy6A
5+2LWBpu3C/MQEep4OpsvOM=
=TeVa
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to