[TIP] Mock objects in testing object composition?

adam goucher adam_goucher at hotmail.com
Wed Apr 25 08:32:48 PDT 2007

I'm currently reading a draft manuscript of 'XUnit Test Patterns' primarily to answer this sort of question. It looks like most of the content for this book is already online. The sections that would be most interesting in this context would be http://xunitpatterns.com/Using%20Test%20Doubles.html and http://xunitpatterns.com/Test%20Double%20Patterns.html.
The use (or not use) of doubles is something he considers a 'strategy', that is, a decision that is painful to change later. Depending on how big the project will be simpler now might be a big headache later.
Further relevant quoting would be that Benji's example of why not using a double would be a 'Fragile Test Smell' (http://xunitpatterns.com/Fragile%20Test.html).

From: lucks at FAS.HARVARD.EDUDate: Tue, 24 Apr 2007 16:52:31 -0400To: benji at benjiyork.comCC: testing-in-python at lists.idyll.orgSubject: Re: [TIP] Mock objects in testing object composition?Many thanks Benji and Paul.

Looks like simpler is better.  So when are mock objects useful?



On Apr 24, 2007, at 4:45 PM, Benji York wrote:

Julius Lucks wrote:

I would like to separate Grid tests from dependance on Tile so that later on down the road when I change the Tile class and break it, then my Grid tests don't start to fail for this reason.  Is this not a good way of thinking?

It sounds ideal, but like so many ideals its cost is likely greater than the benefit.

I wouldn't worry about it.  One day your Tile and Grid tests start failing, you look at one or the other and realize pretty quickly that Tile is at fault, you fix Tile and Grid is happy too.  Not to mention that you making changes to Tile is what caused the tests to start failing, so you'll have a pretty good idea what happened.
Benji York
Connect to the next generation of MSN Messenger 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.idyll.org/pipermail/testing-in-python/attachments/20070425/33c5bb43/attachment.htm 

More information about the testing-in-python mailing list