liveBook · Manning

Mocking

Mocking is a testing technique that replaces a real dependency with a controlled substitute to simulate behavior or inspect interactions.

How 21 Manning books explain it

Unit Testing Principles, Practices, and Patterns

Mocking is the practice of creating, configuring, or applying mocks in software tests.

How it is used
Uses test doubles to isolate unmanaged dependencies and verify externally observable communications.
How deep it goes
Explains mock scope, test placement, edge targeting, call verification, owned adapters, and a refactoring from wrapper mock to edge mock.
Examples
Demonstrates CRM email changes, message-bus mocks, logger mocks, an IBus edge mock, and a handwritten BusSpy.
What you can do after
Apply it via mock frameworks or handwritten spies to verify observable interactions without coupling tests to internal wrappers.

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

The Art of Unit Testing 3e

A programmable test double that replaces an outgoing dependency and records or verifies interactions with it.

How it is used
Verifies calls and arguments at outgoing third-party dependency exit points through interaction testing.
How deep it goes
Defines mocks, contrasts stubs, demonstrates injection and handwritten verification, and details overspecification and readability failures.
Examples
Demonstrates a password verifier with an injected mock logger that records and verifies a PASSED message.
What you can do after
Apply it by injecting a mock dependency and verifying one required outgoing call with its arguments.

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

Practical Automation with PowerShell: Effective scripting from the console to the cloud

A mock is a test double that simulates a dependency or interaction so that code can be tested under controlled conditions.

How it is used
Isolates PowerShell function logic from machine state, network access, and external command behavior during unit tests.
How deep it goes
Explains scoped mocks, thrown errors, file-backed fixtures, parameter filters, and invocation assertions; defers complex object construction alternatives.
Examples
Demonstrates Get-HotFixStatus, catalog HTML replay, Get-SystemInfo CLIXML fixtures, and Linux command-output mocks.
What you can do after
Apply it via Pester to create repeatable tests for success, failure, and dependency-specific scenarios.

Read how Practical Automation with PowerShell: Effective scripting from the console to the cloud explains mocking →

Build AI-Enhanced Web Apps

Mocking is the replacement of a real dependency or external response with a controlled test double.

How it is used
Isolates AI application logic from live model calls for controlled, repeatable tests.
How deep it goes
Explains what to replace and works through function, model, streaming, and retrieval substitutes; defers real-model performance to other testing approaches.
Examples
Uses a mocked `generateText` call, a `MockLanguageModelV1` server-action test, and `FakeLLM` with `FakeRetriever` in a RAG test.
What you can do after
Apply it via Vitest, Jest, or SDK testing helpers to verify application behavior under predefined responses without a live model call.

Read how Build AI-Enhanced Web Apps explains mocking →

Build Python Web Apps with Streamlit

Mocking is the process of replacing real dependencies with fake, controlled versions during testing.

How it is used
Isolates backend and frontend unit tests from API calls and other components whose behavior the test does not control.
How deep it goes
Works through patched requests, configured responses, assertions, and a replacement backend; leaves real component interaction to other test types.
Examples
Uses movie-search responses, an empty-results case, a fake backend, and Streamlit frontend interaction tests.
What you can do after
Apply it via `unittest.mock.patch` and `Mock` to test backend and frontend behavior without relying on live API responses.

Read how Build Python Web Apps with Streamlit explains mocking →

Modern Angular

A mock implementation is a test-specific substitute implementation that simulates the behavior of a dependency.

How it is used
Isolates Angular unit-test subjects from injected services, child components, HTTP, and router dependencies.
How deep it goes
Defines mock APIs and demonstrates component and signal-service setups, while deferring full mock construction until examples.
Examples
Demonstrates AppComponent child-component mocks and a TimeOffManagementService mock driven by time-off request data.
What you can do after
Apply it via TestBed, RouterTestingModule, MockComponents, and MockProvider to run isolated Angular unit tests.

Read how Modern Angular explains mocking →

Functional Design and Architecture: Examples in Haskell

A mock is a configurable test-double implementation that simulates a real component or service without invoking the real one.

How it is used
Isolates IO-bound business logic from external subsystems during white-box unit testing.
How deep it goes
Demonstrates service-handle and free-monad mocks, including fixed, validated, sequential, and call-counting behavior.
Examples
Uses a missing hardware component and a configured random game picker that selects Dwarf Fortress.
What you can do after
Apply it via service handles or free-monad interpreters to run controlled tests without real dependencies.

Read how Functional Design and Architecture: Examples in Haskell explains mocking →

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

A mock is a programmable test double that records or verifies interactions and can return controlled results or errors.

How it is used
Isolates a remote-service client while checking how the service calls its dependency.
How deep it goes
Works through suite setup, call expectations, argument failures, error injection, and cache verification; does not explore mock-library internals.
Examples
Tests a Go translation client with expected arguments, a case mismatch, an injected error, and a single-call cache expectation.
What you can do after
Apply it via Testify to verify dependency calls and exercise controlled results and errors.

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

Build Financial Software with Generative AI (From Scratch)

Mocking is a testing and development technique that replaces real data or dependencies with controlled predefined substitutes.

How it is used
Enables frontend progress and scenario testing before a real or third-party API is available.
How deep it goes
Walks through WireMock stubs, external response files, mappings, and mapping refreshes, while deferring broader WireMock features.
Examples
Uses recent ACH-upload rows, a Hello World stub, and a GET /api/v1/files JSON response.
What you can do after
Apply it via WireMock to return predefined API responses for UI development and error or edge-case scenarios.

Read how Build Financial Software with Generative AI (From Scratch) explains mocking →

Kafka Streams in Action, Second Edition

A mock object is a test double that implements a collaborator's interface while providing explicitly configured behavior instead of performing the collaborator's real operations.

How it is used
Uses interface-compatible test doubles to isolate methods and Kafka components from live brokers and other external systems.
How deep it goes
Explains configuration, injected interfaces, scheduled poll tasks, stubbed returns, output history, and interaction verification.
Examples
Demonstrates MockConsumer and MockProducer currency conversion tests plus Mockito tests for a state-store punctuator.
What you can do after
Apply mocking via MockConsumer, MockProducer, and Mockito to run isolated tests and verify outputs or collaborator interactions.

Read how Kafka Streams in Action, Second Edition explains mocking →

Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

Mocking is the replacement of a software dependency with a controlled substitute that provides compatible behavior for development or testing.

How it is used
Isolates code in tests and replaces cloud-backed storage for more convenient local microservice development.
How deep it goes
Defines substitution, works through a Jest function test, and shows a filesystem-backed service replacement configured in Docker Compose.
Examples
Uses a Jest test with a replacement multiplication function and a local-filesystem substitute for cloud video storage.
What you can do after
Apply it via Jest to isolate a function, or operate/configure it via Docker Compose to substitute a storage microservice.

Read how Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform explains mocking →

Functional Programming in JavaScript

A testing technique that replaces external dependencies with controlled stand-ins whose behavior and interactions can be asserted.

How it is used
Separates external dependency behavior from business-logic tests by simulating database fetches.
How deep it goes
Demonstrates mock setup, expectations, verification, and restoration, but does not detail mock implementation internals.
Examples
Uses a mocked student database to test findStudent within the showStudent program.
What you can do after
Apply it via QUnit and Sinon.JS to simulate database responses and verify dependency interactions.

Read how Functional Programming in JavaScript explains mocking →

Quarkus in Action

Mocking is the practice of substituting controlled test doubles for components that are unsuitable or undesirable to run during a test.

How it is used
Uses controlled test doubles to isolate high-level Quarkus tests from costly, unavailable, slow, or unsuitable components.
How deep it goes
Explains CDI replacement and Mockito behavior, including scope constraints and native-mode limitations, but stops short of exhaustive framework reference.
Examples
Demonstrates a mocked GraphQLInventoryClient returning one Peugeot during a ReservationResource availability-and-reservation test.
What you can do after
Apply it via Quarkus CDI alternatives or Mockito to test application behavior without running the real remote service.

Read how Quarkus in Action explains mocking →

Data Pipelines with Apache Airflow, Second Edition

A mock is a test double that replaces a dependency with controlled behavior for verifying software interactions.

How it is used
Isolates Airflow operator and DAG tests from external systems by replacing their calls with controlled behavior.
How deep it goes
Explains return-value substitution, patching, interaction assertions, and import location, while requiring insight into tested internals.
Examples
Uses a mocked MovieLens hook connection in an operator test and a mocked API call in a DAG test.
What you can do after
Apply it via pytest-mock to replace external calls and verify their call counts and arguments.

Read how Data Pipelines with Apache Airflow, Second Edition explains mocking →

Learn Go with Pocket-Sized Projects

A mock is a test double that imitates a component's interface while allowing interactions or outputs to be controlled and inspected.

How it is used
Uses controlled interface implementations to isolate units and verify dependency interactions during tests.
How deep it goes
Defines stubbing versus mocking, demonstrates hand-written doubles, and names generators without detailing generated-mock setup.
Examples
Uses an io.Writer test helper, an exchange-rate stub, generated mock tools, and a static service response.
What you can do after
Apply it via Go interfaces and injected test doubles to control dependency results and inspect interactions.

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

React in Depth

Mocking is a testing technique that replaces a dependency or functionality with a controlled substitute having behavior specified by the test.

How it is used
Uses controlled substitutes to isolate React components and exercise dependency behavior without invoking real services or browser functionality.
How deep it goes
Explains callback, browser API, and whole-library replacement with runnable tests, but does not develop mocking internals beyond Vitest APIs.
Examples
Demonstrates callback verification, geolocation success and failure, and Axios loading and error states.
What you can do after
Diagnose component behavior by configuring Vitest mocks and asserting callbacks, rendered states, and controlled dependency outcomes.

Read how React in Depth explains mocking →

.NET MAUI in Action

A mock implementation is a test or development substitute that provides a controlled implementation of an interface or dependency.

How it is used
Unblocks UI construction and testing while a real dependency remains unavailable.
How deep it goes
Demonstrates interface definition, a predictable implementation, page integration, and explicit limits around authenticated API behavior.
Examples
Uses MockAuthService, IAuthService.LoginAsync, a login button, progress feedback, and a deterministic successful result.
What you can do after
Build and test UI flows before implementing the real authentication service.

Read how .NET MAUI in Action explains mocking →

gRPC Microservices in Go

A mock is a test double that implements an interface and provides programmable responses for controlling a dependency's behavior.

How it is used
Isolates the Order service from database and Payment service dependencies to test PlaceOrder with controlled responses and less setup.
How deep it goes
Shows manual port implementations, response configuration, and success and error-path assertions; also introduces generated mocks without examining library internals.
Examples
Uses PlaceOrder tests with successful database and payment calls, a failed Save, and a failed Charge with a payment validation error.
What you can do after
Build it from scratch with testify/mock, or apply it via mockery, to control Order service dependencies in unit tests.

Read how gRPC Microservices in Go explains mocking →

Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A mock is a test substitute that replaces a real infrastructure provider with a fake implementation returning predetermined values without creating real infrastructure.

How it is used
Tests Terraform module logic without provisioning real infrastructure.
How deep it goes
Explains provider replacement, default computed values, type-wide defaults, targeted overrides, reusable files, and limitations; does not detail provider internals.
Examples
Uses a mocked AWS region and a plan-time DNS-record assertion, then targets that region data source with an override.
What you can do after
Operate/configure it using `mock_provider`, type defaults, or a targeted override to test module logic without creating infrastructure.

Read how Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu explains mocking →

Kafka for Architects

A mock is a test double that imitates a dependency and records or verifies interactions with it.

How it is used
Isolates Kafka-adjacent dependencies during unit tests so services can be evaluated without external infrastructure.
How deep it goes
Defines dependency replacement and interaction verification, but defers actual Kafka behavior and message flow to integration tests.
Examples
Uses ProfileService producer calls, consumer handlers, and mock producer or consumer implementations.
What you can do after
Evaluate/understand component behavior by checking return values, side effects, or producer calls without a Kafka cluster.

Read how Kafka for Architects explains mocking →

Pro ASP.NET Core 7, Tenth Edition

A mock object is a test double that imitates a dependency and can provide controlled behavior or interaction verification.

How it is used
Uses configurable test doubles to isolate ASP.NET Core controllers from repositories and data-source implementations.
How deep it goes
Works through interface setup, dependency injection, returned data, and call-count verification, but defers Moq's broader feature set.
Examples
Demonstrates mocked products, category-specific pagination counts, empty-cart rejection, invalid shipping details, and successful order submission.
What you can do after
Apply it via Moq to configure dependencies, inject them into controllers, and verify behavior and interaction counts.

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

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.