[TIP] Which mock object framework should I use?
Aaron Maxwell
amax at redsymbol.net
Sat Nov 17 12:27:12 PST 2007
I have really only used pymock, so I can't compare it to the others listed.
For what it is worth, however, it's a pretty good mocking library, at least
as good as ones I have used in other languages. The record/replay/expect
interface is pretty fine grained. The functionality is fairly complete: you
can even mock-override standard library functions (like, say, os.listdir).
One feature I really like: you can define and pass an arbitrary function to
expectAndReturn. This is useful when you a need a mock method to behave in a
more complex way than can be specified using the default command interface.
(It's a feature I have missed in other language libraries. Since python sees
functions as first-class objects, it's not as hard to implement as a feature
in a python mocking library, so maybe the others in the list have it as
well.)
The docs for it could be better. They're not bad, just... could be better.
I'd be interested to hear people's experiences with the others as well.
-Aaron
On Saturday 17 November 2007 11:06:30 Martin Aspeli wrote:
> Hi all,
>
> I'd like to use a mock objects library to mock out services. So far,
> I've seen:
>
> - pymock
> - python-mock
> - pMock
> - minimock
> - Mocky
>
> Some of these (the last two) are doctest-only propositions as far as I
> can see, in that they basically print stuff that you then verify. I can
> see how that's useful, but I'd also like something more explicit, where
> I can make declarations about which methods I expect to be called, in
> which order, with particular arguments and returning particular values.
>
> From a brief glance, pymock looks nice in that it's based on EasyMock,
> which I've used in Java. I could imagine using a combination of this and
> minimock in doctests.
>
> Has anyone done a more thorough evaluation and come up with any
> recommendations?
>
> Thanks,
> Martin
--
Aaron Maxwell
http://redsymbol.net
Business Owners and Self-Employed: You're NOT Alone!
The Business Butler - http://businessbutler.us
More information about the testing-in-python
mailing list