File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Getting an ActionForm inside a JUnit test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting an ActionForm inside a JUnit test" Watch "Getting an ActionForm inside a JUnit test" New topic
Author

Getting an ActionForm inside a JUnit test

Chuck Horkin
Greenhorn

Joined: Aug 09, 2006
Posts: 1
I'm testing a Struts-Spring-Hibernate web application using JUnit. One of my methods that I'm testing takes a DynaActionForm (from the action class that calls it) as a parameter. Problem is that inside of my test I have no access to any of the parameters that are passed to this action class, and therefore cannot just pass my method the ActionForm object. Is there a way to use either the action path or the form-bean name as a string in my JAVA test in order to retrieve said form from my struts-config.xml file?

Thanks in advance.

-Chuck
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest you download and use Struts Test Case for JUnit. It's an addon to JUnit that was specifially designed for testing in a Struts application.


Merrill
Consultant, Sima Solutions
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One more thing:

Passing a Struts ActionForm to a Business Logic or Model class is considered bad form. It breaks the MVC model by making your model class dependent on a specific view object (The struts ActionForm). What you're encountering right now is a good illustration of this: You're unable to test your Model classes without bringing the View Layer (Struts) into the picture.

It's better to develop objects that follow the "Transfer Object" or DTO pattern to shuttle information between your model classes and Struts.
[ August 09, 2006: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting an ActionForm inside a JUnit test
 
Similar Threads
HF Design Patterns, origins
unit testing struts?
naming conventions for junit 4.0
junit versions
NullPointerException