|
From: Chris S. <sk...@sk...> - 2004-01-19 21:45:34
|
Mike Bresnahan wrote: >Was that feature added to Nmock recently? Does it also exist in the Java >mock objects framework? I have used both and didn't know such a feature >existed in either. > > It has always been in NMock although I think overusing this approach is probably a Bad Thing - interfaces are better. In terms of the semantics though, I would suggest that the constructor could be called when the mock is created : IMock mock = new DynamicMock(typeof(ClassWithFatConstructor), param1, param2, param3); since we can only initialize the instance once, and it is possible and legal to re-use the mock instance: a.Foo = mock.MockInstance b.Bar = mock.MockInstance Note that in this case there is still only 1 underlying mock object, not 2. Alternatively, we could introduce an explicit CallConstructor() method? DynamicMock mock = new DynamicMock(typeof(ClassWithFatConstructor)); mock.Construct(p1, 2, p3); and it would then be an error to call this method more than once. I prefer the first option though chris |