Hi again Vincent!

Vincent Massol wrote:
> > As for the role of Cactus in general, I'd like to write tests for a
> > particular servlet in such a way that I can test using *either* mock
> objects
> > or in container without recompiling or changing any code in the test
> > classes. This allows a first round of pure J2EE testing, then progressive
> > rounds testing different containers as necessary. In larger teams with the
> > proper scripts, this process allows a daily "container test." Developers
> > test against the mock objects on the development machines and a
> > comprehensive project test, including containers, occurs over night or
> > during lunch.
> >
> 
> hehe .... That's exactly what I have in mind currently ... The only
> remaining problem is : how to provide that ? I have began thinking on it but
> have not found a perfect solution so far ... I'm more than willing to accept
> anyone's help on that ! I have also played with the servlet mock objects
> implementation from the Sourceforge mockobjects project but have not
> committed it to CVS yet as I had not finished my investigations.
> 
> Both mock objects and Cactus have pros and cons. Merging the two would get
> all the pros .... Last remaining question : is it possible without incurring
> the cost of writing 2 test classes for each class to test ?

I'd like to get this straight. You mean you don't want to keep two test
classes, one with mock objects and another with in-container testing,
that perform the same test?

This would be kind-of-easy, you just need to call a factory that,
depending on some config switch, returns a mock object or sets up a
full-fledged request for the servlet container. The TestCase only needs
to call the request's set...() methods. Then, a call to the factory's
test() method will either instantiate the servlet and doGet() with the
mock objects, or call the container.

        // create the factory for my own servlet
        TestFactory factory = new TestFactory(MyOwnServlet);
        // extract request, response and set a parameter
        TestRequest request = factory.getRequest();
        request.setParameter("name", "paul");
        TestResponse response = factory.getResponse();
        // perform the test
        factory.testServlet(request, response);

This is certainly possible with mock objects, and I think it can be done
with Cactus too -- but you're the expert here :)

However, I don't know -- in case I got it right -- if it's convenient at
all. I mean, it's trivial that the servlet will get basically the same
HttpServletRequest, except when the container has bugs in it.

As I understand it, we want to run two different kind of tests: one
would be a mocked-up test, that can be as comprehensive as you're
willing to (category 1 in your classification); the in-container would
be just a smoke-test, maybe even written by someone else, that can
follow a sequence of operations (end-to-end, or category 3). Put another
way, mock object tests would be "vertical", while in-container tests
would rather be "horizontal".

And yet, it would be nice to write both tests the same way.

The biggest advantage I see with mock objects is that you can debug
them! and yet, they have severe limitations when the global behavior of
a system is tested.

Un saludo,

Alex.

Reply via email to