[TIP] mock objects
beachy at alum.mit.edu
Fri Apr 13 14:37:15 PDT 2007
On 4/13/07, John Arbash Meinel <john at arbash-meinel.com> wrote:
> I thought this was a pretty good article about Mock testing.
> And its ability to test behaviors versus state.
This is interesting, as his example under 'Using EasyMock' points out
that the mock object is serving to test the object being mocked (at
least in the testFillingRemovesInventoryIfInStock() test), or perhaps
more accurately, the interaction between that object and the rest of
I guess this is where at least part of my misconception lay - I was
thinking the point of the mock object was only to provide resources
that would avoid I/O. If you're not concerned with testing the
behavior of or interaction with the mocked object then a simple fake
(a.k.a. stub) object (e.g. one that returns values from a dict based
on the args) will in fact be a much easier way to go!
> A benefit he mentions are that your tests can be really really fast,
> since you don't have to build up a given state to test the transition to
> the next state. (Instead you build up a Mock defining the transition,
> but that is usually much faster without doing any disk I/O,
I understood that speed was an issue, just not why you would use
"mock" vs "stubs" in Fowler's terminology. Funny thing is, I'm pretty
sure I've read that article before, but it just never sunk in.
More information about the testing-in-python