[TIP] [python] Re: Yet another Mock Library
fuzzyman at voidspace.org.uk
Mon Nov 19 14:47:45 PST 2007
Martin Aspeli wrote:
> Michael Foord wrote:
>> Hello all,
>> Actually to call it a library is heavily overblown. It is a single Mock
>> class in less than 50 lines of code. It does meet all of the major
>> mocking patterns we use at Resolver.
> I'm curious - how is this different to the other mocking frameworks out
It doesn't follow (or provide in any way), the 'record -> replay'
pattern of mocking.
In fact all it does it codify the mocking patterns we use extensively at
Resolver. Mocking for testing is (at its core) a very simple problem in
Python. In which case using a 'framework' over a home rolled custom
solution is possibly overkill. I hope this will serve as a useful
example for those wanting to roll their own.
We have a 'Listener' class at Resolver that does some of what this class
does, without providing automatic methods. It does some stuff that is
more specific to Resolver though - like recording which thread it is
called on using the .NET threading APIs. Large projects are likely to be
better served by there own implementation and *hopefully* at Resolver
we'll use this class to replace the myriad of little stubs we use in our
tests and simplify our tests in the process.
It's also scratching my own itch of course. :-)
More information about the testing-in-python