liveBook · Manning

Test double

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

How 9 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 →

Test Driven: Practical TDD and Acceptance TDD for Java Developers

A test double is a substitute for a real collaborator used to provide controlled or recorded interactions in a test.

How it is used
Uses test doubles to isolate difficult collaborators in unit tests and test-driven development.
How deep it goes
Explains the setup-and-verification workflow and distinguishes stubs, fakes, and mocks while noting competing taxonomies.
Examples
Illustrates doubles with a fake pricing service and a map-backed authentication service for a login servlet.
What you can do after
Apply Spring Framework request and response doubles to test Java Servlets.

Read how Test Driven: Practical TDD and Acceptance TDD for Java Developers explains test double →

Microservices Patterns, Second Edition

A test double is a substitute component that simulates the behavior of a real collaborator or dependency during testing.

How it is used
Uses substitutes to isolate components and services for faster automated tests and local development.
How deep it goes
Explains dependency injection and isolation, but defers consumer-driven contract testing and does not detail double implementation.
Examples
Illustrates a mock DAO, simulated service dependencies, and module tests that substitute for other domain modules.
What you can do after
Evaluate when to replace dependencies and when real interactions or contract tests remain necessary.

Read how Microservices Patterns, Second Edition explains test double →

Acing the Frontend Interview

A test double is a substitute for a production dependency used to control or observe interactions during testing.

How it is used
Uses substitutes to isolate unit tests from external dependencies and verify interactions.
How deep it goes
Explains mocks, stubs, and spies through a Jest example, stopping short of detailed double taxonomy.
Examples
Uses a date formatter, external logger, Jest module mock, return-value assertion, and call assertion.
What you can do after
Apply Jest module mocking to isolate a function and assert both its result and dependency interactions.

Read how Acing the Frontend Interview 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
Replaces dependencies to supply predictable indirect inputs or inspect outgoing calls during unit tests.
How deep it goes
Distinguishes stubs from mocks and demonstrates handwritten injection, then outlines framework support and maintenance trade-offs.
Examples
Uses an injected time provider for weekend behavior and an injected logger to capture a success message.
What you can do after
Build it from scratch as an injected JavaScript function or object, or apply it via Jest when handwritten fakes become cumbersome.

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 →

Also covered in

What to know first

Related concepts

Questions about test double

What is test double?

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

Which Manning books explain test double?

Unit Testing Principles, Practices, and Patterns, Test Driven: Practical TDD and Acceptance TDD for Java Developers, Microservices Patterns, Second Edition, Acing the Frontend Interview, The Art of Unit Testing 3e, Shipping Go: Develop, deliver, discuss, design, and go again, Go in Action, Second Edition, Pro ASP.NET Core 7, Tenth Edition and 1 more.

What should I know before learning test double?

Manning books that teach test double usually introduce software testing, dependency, application code and dependency injection first.

What kinds of test double are there?

Kinds of test double include mocking, stub, fake instance and self-shunt.

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.