[TIP] Mock Testing Patterns

Gary Bernhardt gary.bernhardt at gmail.com
Mon Nov 19 07:01:27 PST 2007

On Nov 18, 2007 7:27 PM, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> Do any of the mocking libraries support this pattern - asserting what
> methods were called afterwards rather than setting expectations ahead of
> the actions?

MiniMock does, if you use it with doctests.  MiniMock is super simple
- it just prints out every method call to the mock objects.  You don't
have to set up expectations ahead of time, although you do have to
tell it what the mocked functions should return (otherwise the code
under test wouldn't be fooled!)  If you use it in a doctest, the
printed method calls will have to match what appears in the doctest.
So the "verification" step just falls out for free - it just becomes
another part of the doctest's expected output.



More information about the testing-in-python mailing list