cpp-testing

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

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill cpp-testing-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp-testing
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/cpp-testing
Command: npx skills add https://github.com/ibytechaos/claude --skill cpp-testing-ibytechaos

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. ## 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. - Coverage & Sanitizers: Configures GCC/lcov and Clang/llvm-cov coverage plus ASan, UBSan, and TSan builds to catch memory and race issues. - Use Case: You inherit a C++17 project with no tests. Use this Skill to scaffold a tests/ directory, wire GoogleTest via FetchContent, write fixture-based unit tests, and enable AddressSanitizer in CI to catch latent memory bugs. ## Quick Start Help me set up GoogleTest with CMake for my C++ project and write a unit test for my existing Calculator class.

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?

Use CMake FetchContent to pull a pinned googletest release, link your test executable against GTest::gtest, GTest::gmock, and GTest::gtest_main, then call gtest_discover_tests so CTest registers 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.

GoogleTest vs Catch2 vs doctest for C++ testing?

GoogleTest offers mature mocking via gmock and deep CTest integration. Catch2 is header-only with expressive matchers, while doctest minimizes compile overhead. Choose based on mocking needs and build-time constraints.

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

Add an option like ENABLE_ASAN, then append -fsanitize=address -fno-omit-frame-pointer to compile options and -fsanitize=address to link options. Rebuild and run tests to surface memory errors at runtime.

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 dependence, or hidden global state. Use condition variables or latches, unique temp directories per test, injected clocks, and fixture-based state resets.

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

For GCC, build with --coverage flags, run tests, then use lcov and genhtml for HTML reports. For Clang, use -fprofile-instr-generate -fcoverage-mapping, then merge profiles with llvm-profdata and report with llvm-cov.