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

Testing concurrency

Testing threaded code, catching real races with sanitizers, and hunting flaky tests.

Chapter 11

Testing threaded code

Write deterministic tests for concurrent code: launch threads with std::jthread, release them together with a latch to force overlap, synchronize with std::async and futures, and assert the aggregate that must hold no matter how the threads interleave.

35 minRead โ†’
Chapter 12

Races and memory bugs

Read what the sanitizers report. Run the suite under AddressSanitizer, UndefinedBehaviorSanitizer, and ThreadSanitizer, and see each one catch a bug written to trip it: a dangling view, a signed overflow, and a data race.

35 minRead โ†’
Chapter 13

Deterministic and stress testing

Kill flakiness at the source: inject the clock and the random engine so a test controls time and chance, then stress the suite with gtest_repeat and gtest_shuffle to flush out the rare failures that remain.

35 minRead โ†’
โ† Previous part Mocking Next part โ†’ Tooling and workflow

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