cpp-testing

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill cpp-testing-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cpp-testing
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/cpp-testing
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill cpp-testing-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? C++ test suites often suffer from flaky tests, inconsistent CMake/CTest configuration, missing coverage, and undetected memory or threading bugs. This Skill provides a structured workflow for writing, running, and hardening C++ tests with GoogleTest and GoogleMock. ## Core Features & Use Cases - TDD Workflow Guidance: Follows the red-green-refactor loop with concrete GoogleTest and GoogleMock code examples for unit tests, fixtures, and mocks. - CMake/CTest Configuration: Sets up test discovery with gtest_discover_tests(), coverage builds with lcov or llvm-cov, and sanitizer builds (ASan, UBSan, TSan). - Flaky Test Diagnosis: Provides guardrails against common pitfalls like fixed temp paths, wall-clock dependencies, and sleep-based synchronization. - Use Case: When a CI pipeline reports an intermittent test failure, use this Skill to isolate the failing test with gtest filters, re-run it under ThreadSanitizer, and apply deterministic synchronization fixes. ## Quick Start Ask the agent to write a GoogleTest unit test for a C++ function and configure CTest to 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 write a unit test in C++ with GoogleTest?▼

Create a test file including gtest/gtest.h, then use the TEST macro with EXPECT_EQ or ASSERT_TRUE assertions against your production code. Link the test executable against GTest::gtest and GTest::gtest_main in CMake, then run it via CTest.

How to set up GoogleTest with CMake and CTest?▼

Use FetchContent to pull a pinned googletest release, link your test target against GTest::gtest and GTest::gmock, then call enable_testing() and gtest_discover_tests(). Build with cmake and run tests using ctest --output-on-failure.

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

GoogleTest with GoogleMock provides mature mocking and wide 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 ENABLE_ASAN option that appends -fsanitize=address and -fno-omit-frame-pointer to compile and link options. Rebuild in a separate directory and run the test suite to detect memory errors at runtime.

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

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

When should I not use this C++ testing workflow?▼

Avoid it for implementing new product features without test changes, large refactors unrelated to coverage, performance tuning without regressions to validate, or any non-C++ project. It targets test authoring, configuration, and failure diagnosis only.