cpp-testing

Write and debug C++ tests using GoogleTest, CMake, and CTest workflows.

2|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/adamreger/ecc-antigravity --skill cpp-testing-adamreger
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cpp-testing
Source: https://github.com/adamreger/ecc-antigravity/tree/main/skills/cpp-testing
Command: npx skills add https://github.com/adamreger/ecc-antigravity --skill cpp-testing-adamreger

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable C++ tests requires coordinating GoogleTest, CMake, and CTest configuration, and teams often struggle with flaky tests, missing coverage, and undetected memory or threading bugs. ## Core Features & Use Cases - TDD Workflow Guidance: Follows the red-green-refactor loop with concrete GoogleTest and GoogleMock examples for unit tests, fixtures, and mocks. - Build and Test Configuration: Provides CMake/CTest setup with gtest_discover_tests, coverage instrumentation for GCC and Clang, and ASan/UBSan/TSan sanitizer builds. - Flaky Test Diagnosis: Supplies guardrails for deterministic tests, including avoiding sleeps, wall-clock time, and hidden global state. - Use Case: When a C++ service test intermittently fails in CI, use this Skill to isolate the failing test with gtest filters, re-run it under ThreadSanitizer, and fix the race with a condition variable. ## Quick Start Ask the agent to write a GoogleTest unit test with CMake and CTest configuration for a specific C++ class in your 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 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?▼

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

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

GoogleTest with GoogleMock provides full mocking and broad CTest integration. Catch2 is header-only with expressive matchers, and doctest offers minimal compile overhead. Choose based on mocking needs and build-time constraints.

How do I enable code coverage for C++ tests?▼

For GCC, compile and link with --coverage, 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 sleeps used for synchronization, wall-clock time dependencies, shared temp paths, or hidden global state. Replace sleeps with condition variables or latches, inject clocks, use unique temp directories, and reset state in fixtures.

When should I use sanitizers like ASan, UBSan, and TSan?▼

Enable AddressSanitizer for memory errors, UndefinedBehaviorSanitizer for undefined behavior, and ThreadSanitizer for data races, typically as dedicated CI build configurations. Add the corresponding -fsanitize flags to both compile and link options.