Unit Test Is The Mock

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 ExpensiveSetUpSmells.

For example, MockingLegacyCode may be the best way to get quickly to UnitTestingLegacyCode. But, generally less MockObjects is probably better. You don't want to leave a lot of MockObjects around for long because they preserve the CodeSmell, rather than ImprovingTheDesignOfExistingCode.

In contrast, if you have an expensive object involved in one or more UnitTests, 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


EditText of this page (last edited April 16, 2004) or FindPage with title or text search