Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we really need isolation frameworks to create stubs?

I have read this: http://martinfowler.com/articles/mocksArentStubs.html My concepts about a stub and a mock are clear. I understand the need of isolation frameworks like moq, rhinomocks and like to create a mock object. As mocks, participate in actual verfication of expectations. But why do we need these frameworks to create stubs. I would rather prefer rolling out a hand created stub and use it in various fixtures.

like image 633
Sandbox Avatar asked Dec 28 '22 16:12

Sandbox


1 Answers

Have you tried using a library like Rhino Mocks for a day or two before deciding that hand-rolled stubs is a better option?

@chibacity: The whole idea about mocking libraries is to avoid implementations. If I only need to set a single property's value, I don't want to create a whole implementation of an interface. Calling code like

MyObj obj = MockRepository.GenerateStub<MyObj>();
obj.MyProperty = 33;

seems much simpler to me. Not to mention situations where I only need a dumb stub to be passed as a parameter where I don't care what happens to it (so no set up is required).

This doesn't mean you shouldn't roll out your own stubs for more complex scenarios, but in my experience such cases are rare.

My recommendation is to learn how to use a good mocking library (like Rhino) with all its little tricks, my bet is that you'll soon learn to appreciate the reasons for its existence.

like image 121
Igor Brejc Avatar answered Dec 31 '22 13:12

Igor Brejc