Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to test servlets

 
ramanuja varun
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am given an assignment on testing servlet.I have gone through the net and after hours of surfing found nothing useful.i am not able to configure the cactus framework in the eclipse .If somebody has code relating this please do forward it to me.please let me know if we can test servlets without using the cactus framework? if yes please send me a sample servlet testcase with explanation.
thanks
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't necessarily need Cactus for testing Servlets. After all, Servlets are just plain old Java classes that happen to extend from HttpServlet. What I usually do for Servlets is good old unit tests that throw mock request and response objects at the Servlet and verify that the Servlet 1) makes the appropriate calls to whatever service layer components you have, and 2) forwards the request to/renders the expected view.
 
ramanuja varun
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please send me a sample testcase to test the servlet.I am in great hurry.thanks a lot for helping me.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another approach I sometimes use if I want to test not just the servlet, but also that the resulting HTML page is correct (which mostly is created using JSP) is to use jWebUnit.
 
ramanuja varun
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your prompt reply..

Could you please send me a sample code.. so that I can quick learn...!!
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have sample code at hand - sorry. There's a whole chapter in my book about writing unit tests for Java web components, though...

If you're in a hurry, you could take the approach in this article and apply that to Servlets (rather than Spring's components they talk about in the article).
 
ramanuja varun
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir,
can you tell me which book you were refering to so that i can go through the book for my reference.Thanks a lot for your help sir.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The book "Test Driven" is linked in Lasse's signature.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic