• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting an ActionForm inside a JUnit test

 
Chuck Horkin
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic