[TIP] [python] Re: Mock Testing Patterns
Michael Foord
fuzzyman at voidspace.org.uk
Sun Nov 18 16:59:53 PST 2007
Martin Aspeli wrote:
> 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. :)
>
Well, the pattern is usually more like:
setup mocks
action
assertions
So yes, there is some setup to put the mocks in place.
This pattern works *fine*, but we aren't yet using a mocking library. I
wonder if there are any that will support us in this pattern rather than
switching to recording expectations.
Michael
http://www.manning.com/foord
> Martin
>
>
More information about the testing-in-python
mailing list