cpp-testing

Writes and debugs C++ tests using GoogleTest, CMake, CTest, coverage, and sanitizers.

Updated Apr 9, 2026
One-click install
npx skills add https://github.com/5onyy/essential-ai-agent-skills --skill cpp-testing-5onyy
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cpp-testing
Source: https://github.com/5onyy/essential-ai-agent-skills/tree/main/.cursor/skills/cpp-testing
Command: npx skills add https://github.com/5onyy/essential-ai-agent-skills --skill cpp-testing-5onyy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing and maintaining reliable C++ tests is hard: flaky tests, misconfigured CMake/CTest setups, missing coverage, and undetected memory or threading bugs slow down development. This Skill provides a structured workflow for building a solid C++ test suite with GoogleTest/GoogleMock and CMake/CTest. ## Core Features & Use Cases - TDD Workflow Guidance: Follows the red-green-refactor loop with concrete GoogleTest examples for unit tests, fixtures, and gmock mocks. - CMake/CTest Configuration: Sets up test discovery with gtest_discover_tests, filtered test runs, and CI-friendly output-on-failure execution. - Coverage and Sanitizers: Configures GCC/lcov and Clang/llvm-cov coverage plus ASan, UBSan, and TSan builds for memory and race detection. - Use Case: A developer inherits a C++ service with failing, flaky tests. Use this Skill to isolate the failing test with gtest filters, reproduce it under AddressSanitizer, fix the root cause, and add coverage reporting to CI. ## Quick Start Ask the agent to write a GoogleTest unit test with CMake/CTest configuration for your C++ class and run it with sanitizers enabled.

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?▼

Fetch GoogleTest via CMake FetchContent with a pinned version, link your test executable against GTest::gtest, GTest::gmock, and GTest::gtest_main, then call gtest_discover_tests after enable_testing. Run tests with ctest --test-dir build --output-on-failure.

How do I run a single GoogleTest test case?▼

Use ctest with a regex filter, such as ctest --test-dir build -R "UserStoreTest.*", or run the test binary directly with --gtest_filter=UserStoreTest.FindsExistingUser. This isolates failures before expanding to the full suite.

GoogleTest vs Catch2 vs doctest for C++ testing?▼

GoogleTest with GoogleMock provides full mocking support and deep CTest integration via gtest_discover_tests. Catch2 is header-only with expressive matchers, while doctest minimizes compile overhead. Choose based on mocking needs and build constraints.

How do I enable AddressSanitizer in a CMake C++ project?▼

Add an option like ENABLE_ASAN, then apply -fsanitize=address -fno-omit-frame-pointer to both compile and link options when enabled. The same pattern works for UBSan with -fsanitize=undefined and TSan with -fsanitize=thread.

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

Flakiness usually comes from sleeps used for synchronization, shared temp paths, wall-clock time dependencies, or hidden global state. Replace sleeps with condition variables or latches, use unique temp directories per test, inject clocks, and reset global state in fixtures.

How do I generate code coverage reports for C++ tests?▼

For GCC, compile with --coverage and use lcov plus genhtml to produce HTML reports. For Clang, use -fprofile-instr-generate -fcoverage-mapping, then merge profiles with llvm-profdata and render results with llvm-cov report.