[TIP] Mock objects in testing object composition?
andrew-tip at puzzling.org
Tue Apr 24 23:26:10 PDT 2007
Julius Lucks wrote:
> Hi Benji,
> I am new to this, so this might not be the best reason, but 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?
A fairly simple way to achieve this goal is to arrange your test suite so that
Tile's tests run before Grid's (so in general try to put dependencies before the
things that depend on them). Then if your suite gives failures, by tackling the
first reported failures first, you'll probably won't be wasting time
investigating failures in Grid tests due to bugs in Tile.
But really, most of the time the time wastage is minimal; it usually doesn't
take long to guess that a dependency might be the cause and try running just its
suite. And also when things are interdependent you can't easily avoid it
So in this case I think the cost/benefit tradeoff here is in favour of not
worrying about it.
More information about the testing-in-python