test double

Any object that replaces a real dependency in a test: a stub returns canned data, a fake is a small working implementation, and a mock checks interactions.

In more detail

The names matter less than the signal you need. Keep the replacement simpler than the real thing and make its assumptions visible in the test.

Examples

Go: any type with the right methods satisfies a small interface, so doubles are cheap
type fake struct{}
func (fake) RoundTrip(*http.Request) (*http.Response, error) { ... }
Go: a fake http.RoundTripper returns a fixed response with no network
In this course: There are four honest reasons to use one: the real thing is slow, not yours to call, not deterministic, or cannot be made to fail on demand. Making a test easier to write is not one of them. The term and the five kinds come from Gerard Meszaros's book xUnit Test Patterns.

Related terms

Taught in

References