HtmlUnit testing of Cocoon

I’ve just applied to Cocoon 2.1.x the patch supplied by Alfred Nathaniel (swiss Cocoonistas rulez;-) which adds a framework for HtmlUnit-based testing of Cocoon.

Great work! Adding new tests (for Cocoon itself or your own app) is now as simple as the example shown below.

Here’s the complete source code of a test which retrieves a page over HTTP and checks some of its content:

package org.apache.cocoon;
public class FlowscriptRecursiveTestCase
extends HtmlUnitTestCase
final String pageurl = "/samples/flow/test/";

* Check dump without XSLT transform.
public void testFlowscriptRecursive()
throws Exception
assertXPath("html/body/p[1]", "Factorial of 5 is ...");
assertXPath("html/body/p[2]", "120.0");

Cool Stuff, thanks Alfred!

There are now even less excuses for not writing tests for Cocoon..maybe we should only accept bug reports accompanied by such tests ;-)

3 Responses to HtmlUnit testing of Cocoon

  1. No joke Bertrand: although we may accept bugs without unit tests, we should have such tests before starting working on the fix.

    That’s a very efficient way to grow the test suite and ensure there are no future regressions.

  2. leo says:

    It’s not that way simple to test gui components. Testing my swing compenents will be also much harder. I’m not sure if it make sense to write UnitTests for gui-components, perhaps it will be much faster to write clasical (human made) tests.

  3. WojtekBiela says:

    Why not use Canoo WebTest (open source) to do the acceptance testing ? IMHO it’s much simpler to use, than to maintain the test in java classes. Noteworthy is the fact that WebTest itself utilises HTMLUnit to do the testing. It juest packages it nicely.

    BTW, how do you unit-test your cocoon-specific java code? few years ago when I was doing some Cocoon projects I remember having to extend several not well documented cocoon base test classes, has the situation improved? Because I consider doing a bigger project in Cocoon and what concerns me most is will it be easy to use TDD (test-driven dev) as the programming technique. Because we had a big success using it with Spring based apps. How is the Cocoon framework nowadays prepared for unit testing? Please let me know anything that might come in handy

%d bloggers like this: