Grzegorz Kossakowski skrev:
Hello,

As latest experiences showed we badly need tests for servlet services. I would like to write some but to be honest I have almost no experience with writing automatic tests. I'd be grateful for any pointers, samples, advices etc

The components in the framework can be tested with ordinary junit tests. Thanks to dependency injection it is not that hard to create the necessary environment. But unit tests will not test the more complicated parts of the framework, for that functional tests are needed.

To be specific I want to know if I can write tests that will run whole Cocoon's instance, execute several servlets (sitemaps) and compare
resulting XML with static version provided by me.
I need to do that because I can hardly imagine testing such a core functionality in any other why. Providing mock objects for all
environment seems to be death-complicated.

Exactly. Actually I tested earlier incarnations of the framework following such principles. See http://svn.apache.org/repos/asf/cocoon/whiteboard/osgi/cocoon-blocks-fw/cocoon-blocks-fw-servlet-impl/src/test/ and especially http://svn.apache.org/repos/asf/cocoon/whiteboard/osgi/cocoon-blocks-fw/cocoon-blocks-fw-servlet-impl/src/test/java/org/apache/cocoon/blocks/servlet/BlocksManagerTestCase.java. We didn't find any good way to use the tests when we moved to OSGi (today there seem to be much more tools in that area though). And when I removed the OSGi stuff I didn't have the energy to set up a new test set.

I used httpunit, but it was fairly painful to get it working the way I wanted. Among other things it just swallowed the servlet log. In the end it did it work, and it was a great advantage to just be able to run the test cases and see that I hadn't broken anything.

A disadvantage is that functional tests take longer time to run than ordinary unit tests as one typically need to set up much more environment.

The actual testing was to execute all the URLs in the predecessor to the current servlet service samples and check the output.

/Daniel

Reply via email to