Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to test Action class having session object in struts2 Application

 
Shweta Baranwal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shweta Baranwal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic