Sunday, May 29, 2011

Test Doubles compacted

This post is more a personal cheat sheet and a compacted extract of Effective Tests: Test Doubles.

Test Doubles can be grouped by their interaction with the System Under Test (SUT). Satisfy dependencies without interaction, provide input to the SUT or check/record output of the SUT.

No Interaction

The role of the Dummy is to satisfy a dependency of the SUT but the dummy does not interact with the SUT.

Input

A Stub is thick as a brick and provides canned responses to the SUT.
Fakes simulate a component by providing responses based on the call history or context to the SUT.

Output

Spies record the output of a SUT and leave it to the test to verify the output.
A Mock records output and makes assertions on the output for example checks that a Order(int amount) method is called with an amount greater than0.
Mocks and Spies may also provide input to the SUT.

Do we need these terms?

Not at all. But in case a conversation in your team comes up about whether to use Stubs, Fakes, Spies, Mocks, Dummies you'll need some ubiquitous language in the testing domain to establish a discussion. I prefer to use the Mock and Stub terms to clarify if we want to check the output or to simulate some input.

For all interesting in an overview of testing and testing strategies I can recommend reading the blog series by Derek Greer at LosTechies

0 comments:

Post a Comment