[TIP] Mock objects in testing object composition?
John Arbash Meinel
john at arbash-meinel.com
Fri May 18 11:12:40 PDT 2007
Michael Foord wrote:
...
>>> Purists would probably call those "stubs" instead of "mocks", but I
>>> see
>>> what you're saying.
>>>
>> Since this is a testing list, I think it would be helpful to be
>> careful about jargon so as not to sow confusion. I think we should
>> distinguish between stubs and mocks, providing the link to:
>>
>> http://www.martinfowler.com/articles/mocksArentStubs.html
>>
>> when there is confusion, assuming of course, that Fowler is correct
>> in his characterization. :)
>>
>
> I dislike the distinction he draws. Where you are creating simple
> objects that pretend to be other classes for the purposes of testing, by
> normal usage of English you *are* creating mock objects.
>
> I think he has hijacked the term for something which is actually far
> less common...
>
> Michael Foord
> http://www.voidspace.org.uk/ironpython/index.shtml
Well, that may be true, but I don't think he is the only one who uses
the distinction.
Specifically, there are libraries like jMock and PyMock which
encapsulate the "Mock" concept. Which is that you seed an object with
the exact expected calls and the data to return, and then you validate
that exactly those things were called at the end.
So while the term "mock" in English means about the same thing. For
clarity in discussions, testing people seem to have made an explicit
distinction. I don't know of any jStub or PyStub libraries. Since stubs
are not used in the same way, so tend to be very implementation
specific. (Versus a Mock which needs to be designed to verify that the
expected functions were called).
John
=:->
More information about the testing-in-python
mailing list