[TIP] Mock Testing Patterns

Martin Aspeli optilude at gmx.net
Sun Nov 18 16:42:37 PST 2007

Michael Foord wrote:
> Hello all,
> It seems to me that most of the patterns followed by mocking libraries are:
> record expectations
> actions
> verify
> I find this a much less intuitive pattern than the standard unit testing 
> pattern:
> action
> assertions
> Do any of the mocking libraries support this pattern - asserting what 
> methods were called afterwards rather than setting expectations ahead of 
> the actions?

The problem with this approach is that you usually need your mocked code 
to return something (or even modify a passed-in parameter) for the test 
to work at all. You obviously can't specify what should've been returned 
after the code has executed. :)


Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

More information about the testing-in-python mailing list