This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock test for a servlet program(with out webserver)

 
Karthikeyan Sivanaiah
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Team,

How to do mock test for a servlet program(with out webserver)
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13044
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since servlets are completely dependent on a container for full function, you can never completely test without a server of some sort.

However, you can design major functions for testing outside the servlet environment with careful architecture. I have done this and it is worth the trouble to be able to test the separate pieces. The main architectural point is to remove functions from dependence on the servlet API

Here is one example - suppose you have to perform some function based on a POST from a HTML form.

Note that the javax.servlet.ServletRequest interface has a getParameterMap method - this returns all of the values from a POST as a Map. If you write a class with methods that process Map input you can write tests that take input from local files.

You also don't need the javax.servlet.ServletResponse interface to test output, have your methods write to a Writer or OutputStream which you can direct to a file.

Bill
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic