liveBook · Manning

Mocking

Also called mock

Mocking is a testing technique that replaces a dependency or collaborator with a controlled substitute to simulate behavior, isolate code, or inspect interactions.

How 26 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 dependency exit points when return values or state changes cannot show the interaction.
How deep it goes
Works through handwritten call recording, dependency injection, Jest module replacement, partial mocks, and maintainability pitfalls; leaves wider framework APIs aside.
Examples
Uses a password verifier’s logger call, a stubbed configuration service, Jest module replacements, and a partially replaced real logger.
What you can do after
Build it from scratch with a recorded call, or apply it via Jest to verify an outgoing dependency without overchecking internal calls.

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 external dependencies and nondeterministic model responses during testing.
How deep it goes
Demonstrates mock setup, simulated streaming, retrieval tests, and fidelity trade-offs.
Examples
Uses a conversation server action, simulated text streams, and a retrieval system with fixed model responses and documents.
What you can do after
Apply mocking via Vitest, Jest, Vercel AI SDK, and LangChain.js to test application behavior under controlled conditions.

Read how Build AI-Enhanced Web Apps explains mocking →

Testing Spring Boot Applications

Mocking is a testing technique that replaces collaborators with configurable objects that imitate their APIs and behavior.

How it is used
Replaces Spring Boot collaborators to isolate application tests from external dependencies or satisfy beans required by a test context.
How deep it goes
Explains bean replacement, programmed responses, dummy defaults, and verification; does not develop Mockito internals.
Examples
Uses a mocked WeatherService returning 22.6 and named mock beans that satisfy a restricted test context.
What you can do after
Apply it via Mockito and @MockitoBean to replace collaborators, program responses, and verify interactions.

Read how Testing Spring Boot Applications 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 Streamlit app components from external dependencies during unit testing.
How deep it goes
Explains dependency replacement, response configuration, and call assertions through worked tests; leaves real component interactions to integration and end-to-end tests.
Examples
Uses movie-search API responses, an empty result, and a fake backend for a Streamlit frontend.
What you can do after
Apply mocking with unittest.mock.patch and Mock to control dependencies and check test results and calls.

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 code from external subsystems and controls cases for white-box unit testing.
How deep it goes
Works through service-handle substitution, invocation counting, and configurable free-monad interpreters, including sequences and range checks.
Examples
Uses a hardware service with a missing device part and a random activity picker with predetermined choices.
What you can do after
Build it from scratch by substituting service functions or implementing a configurable test interpreter.

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

Acing the Frontend Interview

Mocking replaces a dependency with a programmable substitute that records or controls interactions during a test.

How it is used
Isolates unit-test logic from external dependencies, services, APIs, and side effects.
How deep it goes
Explains programmable substitutes, interaction tracking, and assertions, but does not develop broader test-debugging procedures.
Examples
Uses a date formatter, an external logger, Jest module mocking, and assertions for output and logging.
What you can do after
Apply it via Jest to isolate a function, control dependencies, and verify return values and side effects.

Read how Acing the Frontend Interview 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 →

Spring Start Here, Second Edition

A mock object is a controllable test double that simulates a dependency and allows its interactions to be inspected or verified.

How it is used
Isolates logic by replacing selected dependencies with controllable objects.
How deep it goes
Walks through mock creation, configured responses, method execution, and verification, including an exception flow.
Examples
Uses money transfers and login controller tests to demonstrate successful and failed flows.
What you can do after
Apply it via Mockito to configure dependency responses and verify expected or forbidden calls.

Read how Spring Start Here, Second Edition 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 development and controlled test scenarios before real APIs or dependencies are available.
How deep it goes
Walks through WireMock response files, request mappings, and refresh steps, while leaving advanced features for later.
Examples
Uses a hello-world stub and a recent ACH uploads response with file dates, names, and transaction totals.
What you can do after
Apply mocking via WireMock to return predefined responses for API requests.

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
Uses mocking to isolate tests and simplify local development of a microservices application.
How deep it goes
Demonstrates an injected mock function and a replacement storage service, including their test and Docker Compose configurations.
Examples
Uses a square function with a mock multiply function and a local-filesystem storage service replacing cloud storage.
What you can do after
Apply mocking with Jest to isolate a function and replace a storage microservice for local development.

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 →

The Design of Web APIs, Second Edition

An API simulator is a software representation that imitates an API's behavior before or apart from its production implementation.

How it is used
Uses API mocks to evaluate designs with stakeholders and enable consumer proof-of-concept applications before implementation.
How deep it goes
Explains static OpenAPI-based mocks and outlines templating, scripting, and saved data, but favors prototypes over elaborate design-stage mock configuration.
Examples
Illustrates static GET /accounts responses and POST /transfers behavior involving generated IDs, dates, and later retrieval.
What you can do after
Apply it via an OpenAPI-based mocking tool to try an undeveloped API and decide when a prototype better serves design evaluation.

Read how The Design of Web APIs, Second Edition 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 →

Data-Oriented Programming in Java

A mock is a test-controlled replacement or implementation that stands in for an object or function and allows its behavior or interactions to be controlled.

How it is used
Supports isolated unit tests by controlling dependencies, interactions, and side effects during execution.
How deep it goes
Defines mocks broadly, demonstrates dependency-heavy setup, and stops short of prescribing a specific mocking framework or taxonomy.
Examples
Uses clocks, ratings APIs, invoice grace periods, notification services, thresholds, and data-driven side-effect assertions.
What you can do after
Apply mocking to isolate tests, diagnose hidden dependency coupling, and replace some mocks with explicit data-driven inputs and assertions.

Read how Data-Oriented Programming in Java 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 →

Also covered in

What to know first

Related concepts

Questions about mocking

What is mocking?

Mocking is a testing technique that replaces a dependency or collaborator with a controlled substitute to simulate behavior, isolate code, or inspect interactions.

Which Manning books explain mocking?

Unit Testing Principles, Practices, and Patterns, The Art of Unit Testing 3e, Practical Automation with PowerShell: Effective scripting from the console to the cloud, Build AI-Enhanced Web Apps, Testing Spring Boot Applications, Build Python Web Apps with Streamlit, Modern Angular, Functional Design and Architecture: Examples in Haskell and 18 more.

What should I know before learning mocking?

Manning books that teach mocking usually introduce software testing, dependency, stub and integration test first.

What is the difference between mocking and software testing?

Mocking is a testing technique that replaces a dependency or collaborator with a controlled substitute to simulate behavior, isolate code, or inspect interactions. 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.

What kinds of mocking are there?

Kinds of mocking include spy.

What is mocking a kind of?

Mocking 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.