aspose file tools*
The moose likes Testing and the fly likes How to create Junit test case for action classes in struts application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to create Junit test case for action classes in struts application" Watch "How to create Junit test case for action classes in struts application" New topic
Author

How to create Junit test case for action classes in struts application

yakkala krishna
Greenhorn

Joined: Feb 07, 2008
Posts: 9
Hi,

Good Morning.
This is Y.Rama Krishna.i have an idea regarding how to create junit testcases for normal methods in classes.
But i am not having a proper idea for creating test cases for Action classes,execute() method in struts application.

Please try to give me a proper idea how to create test cases for execute() method in a struts application.

With Regards,
Rama Krishna.Y
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Rama,
Welcome to JavaRanch!

One thing to keep in mind when unit testing an action is that you will need to use a mock/fake HttpServletRequest object. The jMock and easyMock frameworks are good for this. Other parameters (form, mapping) can be instantiated normally in Java.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
yakkala krishna
Greenhorn

Joined: Feb 07, 2008
Posts: 9
Originally posted by Jeanne Boyarsky:
Rama,
Welcome to JavaRanch!

One thing to keep in mind when unit testing an action is that you will need to use a mock/fake HttpServletRequest object. The jMock and easyMock frameworks are good for this. Other parameters (form, mapping) can be instantiated normally in Java.



Hi Jeanne Boyarsky,

Good Morning.
Good to see your Reply.
I didn't get clear idea.please try to give me any example to explain how to write test cases for action classes in junit.

with regards,
Rama krsihna.Y
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Rama,
This page gives an example of using jMock to mock out a request. A Struts class takes a request as a parameter so this part is similar.
 
jQuery in Action, 2nd edition
 
subject: How to create Junit test case for action classes in struts application