Test double patterns

Test Double: How can we verify logic independently when code it depends on is unusable? How can we avoid Slow Tests? We replace a component on which the SUT depends with a “test-specifi c equivalent.”

Test Stub

We replace a real object with a test-specifi c object that feeds the desired indirect inputs into the system under test.

Test Spy

We use a Test Double to capture the indirect output calls made to another component by the SUT for later verification by the test.

Mock Object

We replace an object on which the SUT depends on with a test-specifi c object that verifi es it is being used correctly by the SUT

Fake Object

We replace a component that the SUT depends on with a much lighter-weight implementation.

Configurable Test Double

We confi gure a reusable Test Double with the values to be returned or verifi ed during the fi xture setup phase of a test.

Hard-coded Test Double

We build the Test Double by hard-coding the return values and/or expected calls.

Last updated