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.
What this book is
A chapter-based, hands-on path from an empty directory to a C++ test suite that mocks its dependencies, runs clean under sanitizers, and executes in CI. You build each example locally on Fedora 44 with Clang, CMake, Conan, and GoogleTest and GoogleMock, run it under ASan, UBSan, and ThreadSanitizer, and measure what the suite exercises with llvm-cov. It assumes you can already build a C++ project; this is not a C++ language tutorial. Everything runs locally, with no containers and no VM.
Prerequisites
Set up a Fedora 44 C++ toolchain and prove it works before writing a single test.
Foundations
From an empty directory to a running GoogleTest suite: CMake presets, CTest, assertions, and fixtures.
Beyond the basics
Parameterized and typed tests, death tests, and testing modern C++20/23 features.
Mocking
GoogleMock from first principles: mocks, matchers, actions, and designing code that can be mocked.
Testing concurrency
Testing threaded code, catching real races with sanitizers, and hunting flaky tests.
Tooling and workflow
Debugging failing tests, measuring coverage, and running the suite in CI.