cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reinhard Poetz <>
Subject Re: Making tests suck less (was Re: ECM++)
Date Mon, 25 Oct 2004 06:17:19 GMT
Ugo Cei wrote:
> Il giorno 22/ott/04, alle 19:40, Reinhard Poetz ha scritto:
>> Have you considered using Easymock? IMHO its usage is more intuitive 
>> than jMock.
>> (see BlockDeployer test cases)
> After perusing the documentation and samples, I decided that I liked 
> jMock more, but I didn't try EasyMock in practice. If you are familiar 
> with it, you might try doing a version of the 
> ResourceExistsActionTestCase that I just refactored, so we can do a 
> comparison and decide which is better. 

Surce, here we go:
public void testAct() throws Exception {
     // create objects and controls
     String src = "don't care";
     ResourceExistsAction action = new ResourceExistsAction();
     MockControl resolverCtrl = MockControl.createControl(SourceResolver.class);
     SourceResolver resolver = (SourceResolver) resolverCtrl.getMock();
     MockControl sourceCtrl = MockControl.createControl(Source.class);
     Source source = (Source) sourceCtrl.getMock();
     MockControl parameterCtrl =
     Parameters parameters = (Parameters) parameterCtrl.getMock();

     // "record" excpected method calls, return values and exceptions
     sourceCtrl.setReturnValue(true, MockControl.ONE);
     resolverCtrl.setReturnValue(source, MockControl.ONE);
     parameters.getParameter("url", src);

     // call method to be tested
     Map result = action.act(null, resolver, new HashMap(), src, parameters);

     // check result
     assertSame("Test if resource exists", AbstractAction.EMPTY_MAP, result);

     // check mock objects if methods have been called correctly

> However, I suspect it's more a 
> matter of taste than anything else.

Probably yes. IMO the advantages of Easymock are
  - you directly call methods on the objects -> so refactoring  is rather simple
    because the TestMethods are updated too
  - Easymock can also mock classes and not only interfaces
    Ugo, how did you mock the Parameters object?

IMO the disadvantage is that it is more verbose than jMock.

Of course, if you rewrite our tests, it's your decision :-)


View raw message