aspose file tools*
The moose likes Servlets and the fly likes mock test for a servlet program(with out webserver) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "mock test for a servlet program(with out webserver) " Watch "mock test for a servlet program(with out webserver) " New topic
Author

mock test for a servlet program(with out webserver)

Karthikeyan Sivanaiah
Greenhorn

Joined: Jul 22, 2010
Posts: 7
Hello Team,

How to do mock test for a servlet program(with out webserver)
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mock test for a servlet program(with out webserver)