views:

111

answers:

1

For automated functional testing purposes, I would like to run a servlet container from my test driver without actually issuing HTTP requests over the network. The main goal is to test fairly elaborate conditions of servlet filtering, forwarding, and includes.

I would like a system that embeds the servlet container in a way that:

  • doesn't create a separate process if possible
  • doesn't cause the embedded container to listen on network ports
  • allows me to issue simulated HTTP requests (through an API)
  • allows me to wait for/receive responses and analyze them from Java code

I know that Tomcat can be embedded through an API and has a connector API, so I am sure that it is doable. But surely there must exist a test framework out there doing exactly this already?

(Note that I would prefer if Tomcat is used, but Jetty is another option.)

+2  A: 

What about using Jakarta Cactus? Check out How it works and the TestCase Howto tutorial.

Pascal Thivent
Thanks I am evaluating it and will see if it meets the needs.
ebruchez
Unless I am mistaken, it seems that Cactus still relies on using HTTP to connect to the container, so it is not ideal from that perspective.
ebruchez
Hmmm... Cactus has a ServletTestCase (and JspTestCase and FilterTestCase) and WebRequest and WebResponse classes for Servlet unit testing (in the junit sense). See http://jakarta.apache.org/cactus/writing/howto_testcase_servlet.html and http://jakarta.apache.org/cactus/how_it_works.html. Pay a special attention to the *Redirector Proxies* section.
Pascal Thivent
@Pascal Thivent Nice, i will try it
Arthur Ronald F D Garcia