cpp-testing

Diagnose, write, and repair C++ tests with GoogleTest and CTest.

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/xxih/ai-harness-zh --skill cpp-testing-xxih
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp-testing
Source: https://github.com/xxih/ai-harness-zh/tree/main/references/translations/everything-claude-code/docs/zh-CN/skills/cpp-testing
Command: npx skills add https://github.com/xxih/ai-harness-zh --skill cpp-testing-xxih

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps teams quickly write, fix, and stabilize C++ unit and integration tests so that regressions are caught early and intermittent failures are diagnosed effectively.

Core Features & Use Cases

  • Test authoring and repair: Guidance for writing focused GoogleTest/GoogleMock tests and repairing failing assertions with minimal production changes.
  • Build and CI integration: Instructions to configure CMake and CTest for stable test discovery and CI-friendly runs, including segmentation of unit vs integration tests.
  • Diagnostics and quality gates: Steps to enable AddressSanitizer/UBSan/TSan, collect coverage, and run targeted test subsets to triage flaky or environment-dependent failures.
  • Use case: Add a new unit test for a C++17 component, wire it into CMake with gtest_discover_tests, run ctest to reproduce the failure, enable ASan for memory issues, and submit a minimal fix with coverage verification.

Quick Start

Run a focused failing test locally, add or modify a GoogleTest case to capture the desired behavior, update CMake to discover and build the test, and run ctest to verify the fix.

Frequently Asked Questions about cpp-testing

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

FAQPage Schema
How do I fix flaky GoogleTest failures in my C++ project?

To fix flaky GoogleTest failures, you can reproduce the failing test locally using CTest, enable sanitizers like AddressSanitizer or UBSan to detect memory issues, and apply targeted fixes to stabilize the test run for your C++ codebase.

How do I configure CMake and CTest for GoogleTest discovery?

Configuring CMake and CTest for GoogleTest discovery involves using gtest_discover_tests to wire your C++17/20 tests into the build system, ensuring stable test discovery and CI-friendly runs that segment unit and integration tests effectively.

Can I use AddressSanitizer and coverage with CTest in CI?

Yes, you can enable AddressSanitizer, UBSan, or TSan alongside coverage flags within your CMake and CTest configuration to produce deterministic test runs and collect diagnostic data for your C++ continuous integration pipeline.

What's the best way to add a new unit test for a C++17 component?

The best way to add a C++17 unit test is to write a focused GoogleTest case capturing the desired behavior, update CMake to build and discover the test, and run ctest to verify the fix with minimal production code changes.

Why does my CTest run fail to discover my GoogleTest binaries?

CTest discovery failures often stem from misconfigured CMake build targets or missing gtest_discover_tests directives, which prevents CTest from properly registering and executing your GoogleTest binaries during the build process.

Do I need GoogleMock to write integration tests for C++20 codebases?

GoogleMock is useful for writing focused C++20 integration tests by mocking dependencies, but standard GoogleTest assertions are sufficient if your integration tests do not require isolating external components or interactions.