cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bertrand Delacretaz <bdelacre...@apache.org>
Subject Re: TDD with Cocoon?
Date Sat, 25 Jun 2005 07:57:35 GMT
Le 23 juin 05, à 21:25, Berin Loritsch a écrit :

>> ...b) JUnit test cases which run in a Generator, for higher-level 
>> tests which need access to more of the application's environment
>
> Now, how does this work?  Do you have an example of that?

In the generate() method the Generator locates a JUnit TestSuite (via a 
simple Class.forName() on a generator parameter), and if the TestSuite 
implements an interface of mine, passes it a custom environment object 
like:

     public static class TestEnvironment {
         public final Logger logger;
         public final componentManager WhateverContainerYoureUsing;

         TestEnvironment(Logger x,WhateverContainerYoureUsing w) {
             logger = x;
             componentManager = w;
         }
     }

Then, the Generator creates a junit.textui.ResultPrinter which writes 
results to the Generators' ContentHandler.

That's it, nothing fancy really. But it allows the TestSuite to be 
fairly decoupled from the Cocoon-specific stuff, while having access to 
components and services via the above TestEnvironment (although, 
rereading it now, the TestSuite could also come directly from the 
component manager to reach the same goal).

The nice thing is that this allows you to run certain tests right in a 
deployed app, in the exact same environment that will be used for 
production, just by calling an URL.

It's a bit of a sharp knife, you want to know what your tests are doing 
before enabling this, but I find it very useful to be able to run 
non-destructive tests on *the* system. To be safe, tests that might 
cause harm to a production system are designed to check that they're 
running on a test environment and fail if not.

I'm not very happy with my current JUnitTestGenerator, the XML output 
is garbled when tests fail, but if you want to play with it and 
hopefully improve it I enclose the code below. The problem is probably 
caused by the delay in the ContentHandlerOutputStream, this looks a bit 
silly now that I see it. You should be able to fix it easily if you 
think it can be useful.

-Bertrand


Mime
View raw message