Tag: test doubles

A Test Double is any object or component that we install in place of the real component for the express purpose of running a test. Depending on the reason why we are using it, a Test Double can behave in one of four ways:

• A Dummy Object is a placeholder object that is passed to the SUT as an argument (or an attribute of an argument) but is never actually used.

• A Test Stub is an object that replaces a real component on which the SUT depends so that the test can control the indirect inputs of the SUT. It allows the test to force the SUT down paths it might not otherwise exercise. A Test Spy, which is a more capable version of a Test Stub, can be used to verify the indirect outputs of the SUT by giving the test a way to inspect them after exercising the SUT.

• A Mock Object is an object that replaces a real component on which the SUT depends so that the test can verify its indirect outputs.

• A Fake Object (or just “Fake” for short) is an object that replaces the functionality of the real DOC with an alternative implementation of the same functionality.

– from xUnit Test Patterns: Refactoring Test Code – Gerard Meszaros