• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting an ActionForm inside a JUnit test

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic