๐Ÿงช Testing C++ with GoogleTest
Home Chapters Examples Diagrams Bibliography GitHub โ†—
Home / Mocking
Part 3 2 chapters

Mocking

GoogleMock from first principles: mocks, matchers, actions, and designing code that can be mocked.

Chapter 9

GoogleMock fundamentals

Replace a real collaborator with a mock so you can test a unit in isolation: declare a mock with MOCK_METHOD, set expectations with EXPECT_CALL, match arguments, assert how many times a call happens, and stub background interactions with ON_CALL.

35 minRead โ†’
Chapter 10

Advanced mocking and testability

Go beyond the first mock: design code with seams you can inject, control a mock's strictness with NiceMock and StrictMock, assert call ordering with InSequence, capture arguments with SaveArg, and know when a fake beats a mock.

35 minRead โ†’
โ† Previous part Beyond the basics Next part โ†’ Testing concurrency

Testing C++ with GoogleTest

A chaptered, runnable guide to testing modern C++ (C++20/23) with GoogleTest and GoogleMock on Fedora 44, from your first test to concurrency, sanitizers, and CI.

Tutorial

  • Chapters
  • Examples
  • Bibliography

Reference

  • GoogleTest docs โ†—
  • CMake docs โ†—
  • View on GitHub โ†—
  • Issues โ†—
Open source ยท Apache-2.0 (code) / CC BY 4.0 (prose) Last built 2026-11-11