This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design 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: 32507
    
214

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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: 32507
    
214

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.
 
Have you checked out Aspose?
 
subject: How to create Junit test case for action classes in struts application
 
jQuery in Action, 3rd edition