cpp-testing-fuzzinglisted
Install: claude install-skill rustcircle/c101
# C++ testing and fuzzing
Done means: unit tests green, the same suite green under ASan+UBSan (and TSan for threaded code),
every parser or decoder of untrusted bytes has a fuzz target, and every fuzz crash has become a
regression test. Build and preset mechanics live in `cmake-presets`; this skill covers test code.
Deep material: [GoogleTest and Catch2 cheat sheet](references/framework-cheatsheet.md) | [fuzzing and property-testing playbook](references/fuzzing-playbook.md)
## 1. Framework choice
| Framework | Strengths | CMake target | Discovery |
|---|---|---|---|
| Catch2 v3 | `SECTION` trees, `GENERATE`, matchers, `BENCHMARK`, fast to write | `Catch2::Catch2WithMain` | `include(Catch)` + `catch_discover_tests(t)` |
| GoogleTest + GMock (1.17 needs C++17) | fixtures, `TEST_P`, typed tests, death tests, mocks, FuzzTest and RapidCheck integration | `GTest::gtest_main`, `GTest::gmock` | `include(GoogleTest)` + `gtest_discover_tests(t)` |
| doctest | header-light, fastest compile, tests can live next to code | `doctest::doctest` (`doctest::doctest_with_main`) | `include(doctest)` + `doctest_discover_tests(t)` |
Pick one per repository. Use GoogleTest when you need mocks or FuzzTest; Catch2 when tests are
mostly value-based tables. With FetchContent, `include(Catch)` needs
`list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)` first. Discovery options worth
setting: `DISCOVERY_MODE PRE_TEST` (cross-compiling, emulators), Catch2 `ADD_TAGS_AS_LABELS`
(tags become `ctes