From: Olaf K. <ok...@ab...> - 2001-10-01 09:07:46
|
Hi, I'd like to comment on this, as MockCreator was assembled by my colleague Christian, now on holiday. Sorry, this will be quite long, but give some history of MockCreator to set a context in which our decisions might be easier to understand. During our history with MockObjects we have been frequently annoyed with setting up quite some amount of expectations and return values. This led to assembling the convenience-methods Ivan mentions: Setting expected input and return value in one method call. Further, the implementation of the base-MockObject we use (de.abstrakt.mock.MockObject) forces us to set a return value if the method returns non-void, otherwise we'll get out of sync within the implementation (I know, this is a weak excuse). We decided, that - using MockObjects a lot - it is a lot more convenient to write i.expectFoo( "something", 7 ); i.expectBar( "a parameter", "dontcare" ); instead of i.setUpFoo( 7 ); i.addExpectedFoo( "Something" ); i.setUpBar( "dontcare" ); i.addExpectedBar( "a parameter" ); (given an interface like:) int foo(String); String bar( String ); Additionaly, for each mocked method there are two "expect"-methods: void expectFoo( String parameter, int returnvalue ); void expectFoo( String parameter, Throwable throwable ); to be able to specify that an exception should be thrown upon call of this method. (we have realised that this is bad for methods legally _returning_ a throwable and will most likely change the generated method name slightly) This leads to quite an amount of methods for each MockObject, but you're right: You could use more. I favor setting the return value in any case, even if you don't care. This means, you are forced to care and possibly express your "dontcare" explicitly in code. If you don't care about the incoming parameter, the world looks different: You can't specify "dontcare" with MockCreator (yet?). It would be easy to generate in the "int foo(String)" example, but what about "int foo( String, int, MyBusinessObject )"? Which parameter is it, you don't care about? I suggest it would be best to provide a hook for easy hand-crafting of this behaviour within the generated object (as well as a differential generation if the implementation already exists). Christian is currently extending the MockCreator to be able to specify blocks of expectations where you don't care about the order of execution. We have frequently been annoyed by data coming in in particular order (especially if you are using Set or Map collections) and thought it might be neat to abstract this out. Until now we didn't care about having to specify too much input like you mentioned. And: I suspect it would be fairly easy to extend the MockCreator to mimic the "standard MockObjects behaviour" - additionaly. The most work has to be done by the VA-Classbrowser: We already triple the number of methods in each interface ;-) What do other users think? Olaf -- abstrakt gmbh Behringstrasse 16b (neu!) 22765 Hamburg Tel: +49-40-39804630 (neu!) Fax: +49-40-39907669 http://www.abstrakt.de/ Wir sind umgezogen. Bitte beachten Sie die neue Adresse + Telefonnummer |