liveBook · Manning

Stub

A stub is a stand-in for a component or operation that exposes an interface while substituting simplified, generated, or controlled behavior for its full implementation.

How 10 Manning books explain it

The Art of Unit Testing 3e

A stub is a test double that replaces an incoming dependency by providing controlled behavior or data without verifying interactions with it.

How it is used
Isolates unit tests from incoming dependencies such as time, databases, networks, and configuration.
How deep it goes
Defines stubs, contrasts mocks, and details several injection techniques plus their maintainability trade-offs.
Examples
Uses fixed days for password verification, fake time providers, databases, network endpoints, and configuration failures.
What you can do after
Apply it via parameter, object, constructor, interface, function, or module injection to control indirect inputs.

Read how The Art of Unit Testing 3e explains stub →

Learn Go with Pocket-Sized Projects

A stub is a minimal test double that provides a simplified implementation of a dependency, typically with predetermined behavior.

How it is used
Replaces player input, exchange-rate fetching, or repository access so dependent code can be tested without the real dependency.
How deep it goes
Shows hand-written stubs with predetermined results and contrasts them with mocks that verify calls; defers larger mock implementations to generators.
Examples
Uses `strings.NewReader` for game input, a configurable exchange-rate stub, and a one-method repository stub for an HTTP handler.
What you can do after
Build it from scratch as a small Go implementation of an interface that returns values selected for a unit test.

Read how Learn Go with Pocket-Sized Projects explains stub →

gRPC Microservices in Go

A client stub is a generated client-side proxy that exposes remote service operations as local callable methods.

How it is used
Connects independently deployed services through generated methods, such as Order calling Payment to charge for an order.
How deep it goes
Works through contract generation, client construction, connection, and error handling; leaves endpoint auto-discovery for later.
Examples
Uses generated Order and Payment clients, a Payment Create call, protoc output, and an environment-configured Payment adapter.
What you can do after
Build it from scratch with protoc, then operate/configure it as a Go service dependency that makes bounded remote calls.

Read how gRPC Microservices in Go explains stub →

Automating API Delivery

A controller stub is generated server-side scaffolding for handling operations exposed by an API controller.

How it is used
Provides definition-derived server scaffolding during API build work to reduce drift between implementation and the published API reference.
How deep it goes
Defines the generated components and walks through Spring Boot generation and one implemented operation, while leaving runtime conformance to testing.
Examples
Uses an OpenAPI Generator command, generated Maven project files, a product-view controller method, and successful and invalid-request responses.
What you can do after
Apply it via OpenAPI Generator to create Spring Boot controller scaffolding, then implement an operation and inspect its responses.

Read how Automating API Delivery explains stub →

Unit Testing Principles, Practices, and Patterns

A test double that supplies predetermined responses to calls without primarily verifying those interactions.

How it is used
Uses stubs to supply dependency input while testing the system under test without setting up difficult or maintain-heavy real dependencies.
How deep it goes
Explains interaction classification, configured returns, and assertion risks, but stops short of implementation internals.
Examples
Demonstrates a configured database stub returning 10 users and contrasts it with an email mock producing a side effect.
What you can do after
Apply stubs via a mocking library to configure query responses and assert resulting behavior without coupling tests to query calls.

Read how Unit Testing Principles, Practices, and Patterns explains stub →

Coding with AI

Stubbing is the practice of creating simplified substitute implementations so other application components can be developed or tested before the real functionality exists.

How it is used
Establishes a runnable application skeleton before functional components are implemented.
How deep it goes
Defines stubs, demonstrates dummy database behavior, and gives a strategic checklist without implementing real dependencies.
Examples
Demonstrates a Python DatabaseManager with placeholder database connection and query methods returning dummy values.
What you can do after
Build it from scratch by creating runnable feature stubs, organizing interfaces, and progressively replacing placeholders.

Read how Coding with AI explains stub →

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

A stub is a test replacement for a dependency that returns predetermined results without reproducing the dependency's full behavior.

How it is used
Isolates handler tests from translation-service behavior and provides a temporary dependency while business logic is developed.
How deep it goes
Defines stubs as simple implementations and works through handler response tests; leaves interaction and error verification to mocks.
Examples
Uses a Go translation stub returning "bar" for "foo" and handler tests for success, missing translations, and language handling.
What you can do after
Build it from scratch as an injected Go dependency to test handler responses independently of the real service.

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

Troubleshooting Java, Second Edition

A stub is a controllable fake application or component that substitutes for a real dependency during investigation or testing.

How it is used
Uses a controlled replacement to reveal which application code sends an unexpected request and to test the correction.
How deep it goes
Defines the technique and gives a blocking-request workflow, but defers implementation details of stubs and profilers.
Examples
Uses a wrong system-component request, an indefinitely blocked response, and profiler output identifying the stuck code.
What you can do after
Diagnose/debug with it by isolating a dependency, locating request-producing code, and testing a repaired interaction.

Read how Troubleshooting Java, Second Edition explains stub →

Building Web APIs with ASP.NET Core

A stub is generated proxy or base code that provides the callable interface for communicating with a remote service.

How it is used
Provides generated server and client interfaces for remote-service communication.
How deep it goes
Explains generation and server integration, but defers detailed proto3 syntax and broader stub internals.
Examples
Uses grpc.proto, GetBoardGame, GrpcBase, GrpcService, and generated board-game request and response messages.
What you can do after
Build a remote service by defining its contract, generating stubs, extending the server base, and registering the implementation.

Read how Building Web APIs with ASP.NET Core explains stub →

100 Go Mistakes and How to Avoid Them

A stub is a test double that supplies predetermined responses in place of a dependency.

How it is used
Uses predetermined dependency responses to make unit tests deterministic and resistant to timing variation.
How deep it goes
Explains function injection, interface extension, and global-state trade-offs without detailing a complete mocking framework.
Examples
Uses Cache.TrimOlderThan, injected clocks, fixed timestamps, time.Now, and a mutable global variable.
What you can do after
Apply it via dependency injection to replace time.Now with a fixed clock and run robust, isolated unit tests.

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

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.