You Choose To Mock Me...

Amongst the gaggle of mock object frameworks for Java, I had come to prefer EasyMock over Mock Objects, as it's rather minimal (no pre-generated mocks for J2EE interfaces), and has the extra "cool factor" of generating mocks at runtime via Java's dynamic proxy mechanism (java.lang.reflect.Proxy). But, the syntax for training EasyMocks gets cumbersome with separate steps for saying a mock is to be invoked with such-and-such parms, and saying what should happen as a result (mockControl.setReturnValue(...), and others). Also, the fact that invoking a method on the mock means different things depending on whether you've told the mock to "replay" can be confusing to beginners.

I'm pleased to see that the "dynamic mock" capability of MockObjects is being split out on its own. JMock makes mock training quite a bit simpler, and allows for much flexibility in parameter matching with some sweet syntactic sugar.

Written on January 14, 2004