Last night on twitter Aaron Jenson made the statement
'moq's expect method needs to be renamed'
'setting the expectation is not what you should be doing. you don't *care* if it's called.'
I then started a short conversation with Aaron about this. I have been using RhinoMocks for 2+ years and never really gave a second thought to the 'real' difference between a Mock and a Stub.
I have mostly used Mocks with the Expect syntax and rarely ever used Stubs and their syntax. But after re-reading the Rhino 3.5 WIKI I now have an understanding of what Aaron was referring to and why the point he made me finally go 'Ah ha' I have been thinking about it in the right way, but implementing it in the wrong fashion.
What is a Mock?
A mock is an object that we can set expectations on, and which will verify that the expected actions have indeed occurred.
In English...This is a method call that must take place, but you do not directly care about its results.
What is a Stub?
A stub is an object that you use in order to pass to the code under test. You can setup expectations on it, so it would act in certain ways, but those expectations will never be verified.
In English...This is a method call that must take place, and you DO care about its results because these results will be used in your class under test.
If you start to think about Mocks/Stubs in this light it does make sense. In fact it even starts to clear things up (assuming you were still a bit foggy on the subject).
I think that if authors of the various mocking frameworks really want to make sure people use the correct terminology and syntax, they should limit the framework to ONLY work as the intent specifies.
Till next time,
Posted
10-21-2008 7:20 PM
by
Derik Whittaker