From: Vincent M. <vm...@oc...> - 2001-09-14 20:13:27
|
----- Original Message ----- From: "Lucas Filz" <lu...@ha...> To: <moc...@li...> Sent: Friday, September 14, 2001 7:31 PM Subject: [Mockobjects-java-users] EasyMock vs. MockObjects > Up to now I'm just reading about all that, and maybe I have missed something, > but: > > Why creating, handling, refactoring all those MockObjects when there is such a > thing as EasyMock? (Writing an interface if there is none is not the point I > guess.) > > What are the disadvantages in using EasyMock? > > Or, what are the advantages in having the "real mock object" at hand? > The short answer is : the two methods (dynamic and static) are complementary. Why ? Because it is not always possible to generate good mock implementations. I'll give a simple example. Lets imagine you want to use a mock implementation of ServletOutputStream because you'd like to assert the result from an HTTP response. This class only has print() methods but no getter to access the content. Also what you'd like to do is to assert the full string that has been written to the stream and not byte by byte. This requires some intelligence that cannot be implemented automatically by EasyMock or a static generation (MockMaker). You'll also find that you'll discover patterns in your test case and you'll want to factorise these patterns in the mock objects to provide consistency of checks and easier writing of tests. Now, it probably depends on the kind of API you are mocking and some will be easily mocked with EasyMock. Others won't. I guess that a practice would be to use automatic generation (be it dynamic or static) and then manually write or modify the mocks (for those statically generated). Thus, the problem is that EasyMock or MockMaker won't provide in-the-box and ready to use mock objects (some will need to be written by hand or modified). The idea of the Mock Objects project is twofold : provide a core framework of expectations and useful classes for writing mock implementations (This framework is actually used by MockMaker to generate mock objects and it could be used by EasyMock too) and some prepackaged and already written mock implementations for some standard APIs. The idea is that these API will be feature complete (ok, I agree, there is still some work to be done ... :) ) and will have been fine tuned to already provide the patterns I mentionned above (i.e. shortcuts for easy testing). Tell me what you think. I'd like to hear from others too. Thanks -Vincent Massol |