liveBook · Manning

Test double

A test double is a substitute for a real component or dependency that provides controlled or simplified behavior, or enables interaction observation, during testing.

How 6 Manning books explain it

Unit Testing Principles, Practices, and Patterns

A test double is an object that resembles a production dependency but is simplified to reduce complexity during testing.

How it is used
Supports isolated unit tests by replacing dependencies whose complexity or mutability would obscure the behavior under test.
How deep it goes
Defines the abstraction, classifies five forms into mocks and stubs, and compares isolation trade-offs without prescribing one universal style.
Examples
Uses inventory-purchase tests to contrast real dependencies, configured mocks, state assertions, and interaction verification.
What you can do after
Apply it by isolating suitable dependencies while keeping assertions centered on observable behavior and refactoring resistance.

Read how Unit Testing Principles, Practices, and Patterns explains test double →

The Art of Unit Testing 3e

A test double is a replacement for a real dependency that provides simplified behavior or enables observation during a test.

How it is used
Uses replacements to isolate tests from unreliable incoming dependencies and examine outgoing dependencies.
How deep it goes
Defines the umbrella term, distinguishes stubs from mocks, and lists injection techniques while deferring the five-pattern taxonomy.
Examples
Uses an in-memory database, injected functions, fake modules, constructors, and object parameters as replacement examples.
What you can do after
Apply test doubles by injecting controlled functions, objects, modules, or constructors and naming their roles precisely.

Read how The Art of Unit Testing 3e explains test double →

Shipping Go: Develop, deliver, discuss, design, and go again

A fake is a simplified test double that stands in for an external object, service, or system while providing limited capabilities.

How it is used
Simulates an external service so a client can be tested before integration.
How deep it goes
Builds a fake HTTP server and client tests, while deferring circuit breakers and other advanced system patterns.
Examples
Uses a Go translation client, an HTTP test server, and mocked success and error responses.
What you can do after
Build unit tests for an API client using a fake HTTP server and controlled responses.

Read how Shipping Go: Develop, deliver, discuss, design, and go again explains test double →

Go in Action, Second Edition

A test double is a substitute component that provides controlled behavior or data in place of a real dependency during testing.

How it is used
Enables isolated unit testing of HTTP handlers without databases or external services.
How deep it goes
Defines stubs and mocks and demonstrates interface substitution, but defers comprehensive HTTP test examples.
Examples
Uses a canned ArticleReader implementation to test handlers without the production BoltStore.
What you can do after
Apply it via Go interfaces to test handlers independently from storage and external services.

Read how Go in Action, Second Edition explains test double →

Pro ASP.NET Core 7, Tenth Edition

A fake implementation is a simplified functional implementation of a dependency used in place of the real implementation during testing.

How it is used
Isolates controllers during unit testing by replacing production data sources with controlled implementations.
How deep it goes
Defines an interface, production implementation, controller property, fake implementation, test data, and assertion; defers dependency injection.
Examples
Uses ProductDataSource, FakeDataSource, IDataSource, and controlled Kayak, Lifejacket, P1, P2, and P3 products.
What you can do after
Build it from scratch by defining a dependency interface, implementing a fake, injecting test data manually, and asserting controller output.

Read how Pro ASP.NET Core 7, Tenth Edition explains test double →

100 Go Mistakes and How to Avoid Them

A substitute component used in testing in place of a real dependency or collaborator.

How it is used
Stabilizes Cache time-dependent unit tests by replacing the real clock with a controlled dependency.
How deep it goes
Compares an injected clock function with mutable global state and caller-supplied time, without detailing broader clock abstractions.
Examples
Uses Cache.TrimOlderThan with fixed timestamps and a fake clock to test event trimming.
What you can do after
Apply function-based dependency injection to make time-dependent Cache tests deterministic.

Read how 100 Go Mistakes and How to Avoid Them explains test double →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.