aspose file tools*
The moose likes Testing and the fly likes How to test Action class having session object in struts2 Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to test Action class having session object in struts2 Application " Watch "How to test Action class having session object in struts2 Application " New topic
Author

How to test Action class having session object in struts2 Application

Shweta Baranwal
Greenhorn

Joined: Jun 19, 2008
Posts: 18
Hi All,

I am developing an application using struts2 ,iBatis and JUnit testing tool . I am able to test Service class and dao class using JMock i.e by mocking the nonessential classes but in Action I've used session objects. how do I mock these session objects??


Please help me. If possible then please give me the code abstract of testing Action Class.


Sunil Vasudevan
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
If you are using Spring, you can use spring-mock.jar. It has Mock HttpRequest, HttpResponse and HttpSession objects.

Else, if you want to go with a plain vanilla approach, create a mock HttpSession yourself.

Here is a sample code I had used before using spring-mock:



Hope this helps.

Sunil.V<br />SCJP2, SCWCD1.4, SCBCD1.3
Shweta Baranwal
Greenhorn

Joined: Jun 19, 2008
Posts: 18
Thanks Sunil.

But in my application I am not using Spring even I don't know Spring . I am using Struts2. Can you please help me in testing Action Class having Session attribute . How do I mock session ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to test Action class having session object in struts2 Application