UnitTestIsTheMock
Last edit April 16, 2004
In
TestDrivenDevelopment
, generally the
UnitTestIsTheMock
is a good practice to
DoTheSimplestThingThatCouldPossiblyWork
.
This is basically just saying that the
UnitTest
itself acts as the object interacting with the object(s) under test.
This is a response to seeing more common instances of
ExpensiveSetUpSmell
s.
For example,
MockingLegacyCode
may
be the best way to get quickly to
UnitTestingLegacyCode
. But, generally less
MockObject
s is probably better. You don't want to leave a lot of
MockObject
s around for long because they preserve the
CodeSmell
, rather than
ImprovingTheDesignOfExistingCode
.
In contrast, if you have an expensive object involved in one or more
UnitTest
s, such as a file or database, a
MockObject
is often the best way to improve the testability of the object(s) under test.
--
JasonNocks
I have seen this called
SelfShuntPattern
--
AnthonyWilliams
CategoryMockObjects