cpp-testing

Write and debug C++ tests with GoogleTest, CMake, CTest, coverage, and sanitizers.

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill cpp-testing-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp-testing
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/cpp-testing
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill cpp-testing-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? C++ test setup is error-prone: wiring GoogleTest into CMake, discovering tests with CTest, chasing flaky failures, and enabling coverage or sanitizers all require scattered knowledge. This Skill provides a structured TDD workflow and ready-to-adapt configurations for modern C++ (C++17/20) testing. ## Core Features & Use Cases - TDD Workflow Guidance: Follows the red-green-refactor loop with concrete GoogleTest/GoogleMock examples, including fixtures and mocks. - CMake/CTest Integration: Shows FetchContent-based GoogleTest setup, gtest_discover_tests() registration, and filtered test execution commands. - Coverage and Sanitizers: Provides target-level coverage flags for GCC (gcov/lcov) and Clang (llvm-cov), plus ASan, UBSan, and TSan CMake options. - Use Case: A developer adding regression tests to a C++ service can scaffold a test target, run a single failing test with gtest filters, and re-run under AddressSanitizer to diagnose a memory bug. ## Quick Start Use the cpp-testing skill to create a GoogleTest unit test target wired into CMake with CTest discovery for my C++ project.

Frequently Asked Questions about cpp-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up GoogleTest with CMake and CTest?

Use FetchContent to pull a pinned googletest release, link your test executable against GTest::gtest, GTest::gmock, and GTest::gtest_main, then call enable_testing() and gtest_discover_tests() so CTest discovers each test case automatically.

How do I run a single GoogleTest test case?

Run the test binary directly with --gtest_filter, for example ./build/example_tests --gtest_filter=UserStoreTest.FindsExistingUser. Alternatively use ctest -R with a regex pattern to match the test name.

Should I use mocks or fakes in C++ unit tests?

Use GoogleMock mocks when verifying interactions, such as expecting a method call with specific arguments. Use fakes when you need stateful behavior, like an in-memory store, and prefer dependency injection over global state for testability.

How do I enable code coverage for C++ tests with GCC or Clang?

For GCC, add --coverage to compile and link options, then capture results with lcov and render HTML via genhtml. For Clang, use -fprofile-instr-generate -fcoverage-mapping and report with llvm-profdata and llvm-cov.

Why are my C++ tests flaky and how do I fix them?

Flakiness usually comes from sleep-based synchronization, shared temp directories, real time or network dependencies, and nondeterministic randomness. Use condition variables or latches, unique temp directories per test, and deterministic seeds.

When should I enable AddressSanitizer or ThreadSanitizer?

Enable ASan when investigating memory errors like use-after-free or buffer overflows, and TSan when diagnosing data races in multithreaded code. Add the corresponding -fsanitize flags to compile and link options, then re-run the failing test.