Stub
A stub is a minimal or generated stand-in for a software component or operation that exposes an interface while supplying placeholder, controlled, or delegated behavior.
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
- Replaces incoming dependencies with controlled inputs so unit tests can run predictably without relying on unreliable external behavior.
- How deep it goes
- Defines the stub–mock distinction and develops injection from a day parameter through functions, objects, modules, and typed interfaces.
- Examples
- Uses a controlled weekday for password verification and a fake time provider that can return a chosen day.
- What you can do after
- Build it from scratch by injecting controlled inputs, then test resulting behavior without verifying calls to the 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 dependencies during unit tests or while an external service is unavailable.
- How deep it goes
- Defines stubs and implements configurable interface methods, then distinguishes their behavior from mock call verification.
- Examples
- Uses exchange-rate results, repository errors, and simulated player input as test dependencies.
- What you can do after
- Build a small Go interface stub and configure its return values or errors for test cases.
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.
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.
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 →
Testing Spring Boot Applications
A stub is a test substitute that provides predetermined or programmable behavior in place of a real dependency.
- How it is used
- Replaces dependencies in Spring Boot tests so a limited application context can start or receive predictable responses.
- How deep it goes
- Distinguishes stubs from unused dummy mocks and shows bean-supply options; stops short of demonstrating a programmed Mockito response.
- Examples
- Shows missing Gizmo and named Widget beans supplied with @MockitoBean, alongside an @TestBean factory-method alternative.
- What you can do after
- Apply it via @MockitoBean or @TestBean to supply test dependencies, programming responses when their behavior matters.
Effective Behavior-Driven Development
A test double that substitutes for a real dependency and provides predetermined behavior or responses.
- How it is used
- Substitutes for an external dependency when scenario automation needs controlled, test-friendly behavior.
- How deep it goes
- Works through a settable time service, event callbacks, driver, and application configuration; leaves the general real-versus-stub decision open.
- Examples
- Uses a delivery-delay notification at 18:46, a stub time service, and configuration that installs it for a scenario.
- What you can do after
- Build it from scratch as a replaceable time service that supplies controlled time and triggers time-change events in a scenario.
Read how Effective Behavior-Driven Development 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
- Uses stubs to establish application structure, connect components early, and test flow before implementing full functionality.
- How deep it goes
- Defines stubs, demonstrates dummy returns, and gives generation steps; stops short of implementing the underlying functionality.
- Examples
- Uses database connection and data-fetching placeholders, plus stubs organized for a HAM radio test-preparation application.
- What you can do after
- Build a runnable application skeleton by organizing component stubs from requirements and replacing placeholders iteratively.
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 →
Test Driven: Practical TDD and Acceptance TDD for Java Developers
A stub is a test double that supplies predetermined responses to calls made by the system under test.
- How it is used
- Replaces collaborators with predetermined responses to avoid costly or inconvenient dependencies in tests.
- How deep it goes
- Defines stubs as simple implementations with hardcoded values, but does not detail how to build one.
- Examples
- Uses hardcoded interface values, a stubbed system clock, and in-memory logging as examples.
- What you can do after
- Apply stubs to replace costly or inconvenient collaborators while weighing replacement fidelity against test speed.
Read how Test Driven: Practical TDD and Acceptance TDD for Java Developers 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 →
Designing AI Systems
A stub is a generated client-side proxy that represents remote operations as local callable methods.
- How it is used
- Uses generated proxies to make remote service operations callable through a Python SDK.
- How deep it goes
- Explains generation, serialization, transport, deserialization, and SDK integration, but does not detail compiler configuration.
- Examples
- Demonstrates SessionClient setup and a get_or_create workflow for retrieving sessions and recording messages.
- What you can do after
- Apply generated stubs through a Python SDK to invoke remote operations and receive mapped domain objects.
Also covered in
- Microservices Patterns, Second EditionIn early access (MEAP)
- ASP.NET Core in Action, 3e
- Quarkus in Action
- Contract Testing in Action
- Build Financial Software with Generative AI (From Scratch)
- Akka in Action, Second Edition
What to know first
- software testingSoftware testing is the systematic evaluation of software under specified inputs or conditions to assess its behavior against expected results or requirements and identify defects.
- dependencyA dependency is a component, resource, or prerequisite that another software component or activity relies on to function, build, or proceed.
- contractA contract is an agreed specification of the conditions, expectations, rights, or obligations that govern behavior or interactions between parties or software components.
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
Related concepts
- test doublekind of · A test double is a substitute for a real dependency or collaborator that provides controlled behavior or enables interaction observation during testing.
- mockingcontrasts with · Mocking is a testing technique that replaces a dependency or collaborator with a controlled substitute to simulate behavior, isolate code, or inspect interactions.
- OpenAPI specificationproduced by · The OpenAPI Specification is a machine-readable standard for describing HTTP APIs, including their operations, inputs, outputs, data structures, and security requirements.
- protocproduced by · protoc is the Protocol Buffers compiler that parses .proto schema definitions and generates language-specific source code and related artifacts.
- software testinguses · Software testing is the systematic evaluation of software under specified inputs or conditions to assess its behavior against expected results or requirements and identify defects.
Questions about stub
What is stub?
A stub is a minimal or generated stand-in for a software component or operation that exposes an interface while supplying placeholder, controlled, or delegated behavior.
Which Manning books explain stub?
The Art of Unit Testing 3e, Learn Go with Pocket-Sized Projects, gRPC Microservices in Go, Automating API Delivery, Unit Testing Principles, Practices, and Patterns, Testing Spring Boot Applications, Effective Behavior-Driven Development, Coding with AI and 6 more.
What should I know before learning stub?
Manning books that teach stub usually introduce software testing, dependency, contract and function first.
What is the difference between stub and mocking?
A stub is a minimal or generated stand-in for a software component or operation that exposes an interface while supplying placeholder, controlled, or delegated behavior. Mocking is a testing technique that replaces a dependency or collaborator with a controlled substitute to simulate behavior, isolate code, or inspect interactions.
What is stub a kind of?
Stub is a kind of test double. A test double is a substitute for a real dependency or collaborator that provides controlled behavior or enables interaction observation during testing.
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.













