• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mock test for a servlet program(with out webserver)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Team,

How to do mock test for a servlet program(with out webserver)
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic