cpp-testing — ai-agents cpp-testing, everything-claude-code, official, ai-agents, ide skills, anthropic, claude-code, developer-tools, Claude Code, Cursor, Windsurf

Verified
v1.0.0
GitHub

About this Skill

Essential for C++ Development Agents requiring robust test automation and CI/CD integration. Use only when writing/updating/fixing C++ tests, configuring GoogleTest/CTest, diagnosing failing or flaky tests, or adding coverage/sanitizers.

# Core Topics

affaan-m affaan-m
[60.6k]
[7501]
Updated: 3/5/2026

Agent Capability Analysis

The cpp-testing skill by affaan-m is an open-source official AI agent skill for Claude Code and other IDE workflows, helping agents execute tasks with better context, repeatability, and domain-specific guidance. Optimized for ai-agents, anthropic, claude-code.

Ideal Agent Persona

Essential for C++ Development Agents requiring robust test automation and CI/CD integration.

Core Value

Empowers agents to automate GoogleTest/GoogleMock workflows with CMake/CTest configuration, enabling comprehensive unit/integration testing with coverage tracking and sanitizer integration for memory/race condition diagnostics. Provides direct support for diagnosing flaky tests and adding regression protection to C++17/20 codebases.

Capabilities Granted for cpp-testing

Configuring CMake/CTest workflows for consistent test execution
Diagnosing failing or flaky C++ test behavior
Adding coverage tracking and sanitizers for memory/race diagnostics
Writing and updating unit/integration tests for C++ components

! Prerequisites & Limits

  • C++17/20 specific testing only
  • Requires GoogleTest/GoogleMock framework
  • Limited to CMake-based build systems
Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

cpp-testing

Install cpp-testing, an AI agent skill for AI agent workflows and automation. Works with Claude Code, Cursor, and Windsurf with one-command setup.

SKILL.md
Readonly

C++ Testing (Agent Skill)

Agent-focused testing workflow for modern C++ (C++17/20) using GoogleTest/GoogleMock with CMake/CTest.

When to Use

  • Writing new C++ tests or fixing existing tests
  • Designing unit/integration test coverage for C++ components
  • Adding test coverage, CI gating, or regression protection
  • Configuring CMake/CTest workflows for consistent execution
  • Investigating test failures or flaky behavior
  • Enabling sanitizers for memory/race diagnostics

When NOT to Use

  • Implementing new product features without test changes
  • Large-scale refactors unrelated to test coverage or failures
  • Performance tuning without test regressions to validate
  • Non-C++ projects or non-test tasks

Core Concepts

  • TDD loop: red → green → refactor (tests first, minimal fix, then cleanups).
  • Isolation: prefer dependency injection and fakes over global state.
  • Test layout: tests/unit, tests/integration, tests/testdata.
  • Mocks vs fakes: mock for interactions, fake for stateful behavior.
  • CTest discovery: use gtest_discover_tests() for stable test discovery.
  • CI signal: run subset first, then full suite with --output-on-failure.

TDD Workflow

Follow the RED → GREEN → REFACTOR loop:

  1. RED: write a failing test that captures the new behavior
  2. GREEN: implement the smallest change to pass
  3. REFACTOR: clean up while tests stay green
cpp
1// tests/add_test.cpp 2#include <gtest/gtest.h> 3 4int Add(int a, int b); // Provided by production code. 5 6TEST(AddTest, AddsTwoNumbers) { // RED 7 EXPECT_EQ(Add(2, 3), 5); 8} 9 10// src/add.cpp 11int Add(int a, int b) { // GREEN 12 return a + b; 13} 14 15// REFACTOR: simplify/rename once tests pass

Code Examples

Basic Unit Test (gtest)

cpp
1// tests/calculator_test.cpp 2#include <gtest/gtest.h> 3 4int Add(int a, int b); // Provided by production code. 5 6TEST(CalculatorTest, AddsTwoNumbers) { 7 EXPECT_EQ(Add(2, 3), 5); 8}

Fixture (gtest)

cpp
1// tests/user_store_test.cpp 2// Pseudocode stub: replace UserStore/User with project types. 3#include <gtest/gtest.h> 4#include <memory> 5#include <optional> 6#include <string> 7 8struct User { std::string name; }; 9class UserStore { 10public: 11 explicit UserStore(std::string /*path*/) {} 12 void Seed(std::initializer_list<User> /*users*/) {} 13 std::optional<User> Find(const std::string &/*name*/) { return User{"alice"}; } 14}; 15 16class UserStoreTest : public ::testing::Test { 17protected: 18 void SetUp() override { 19 store = std::make_unique<UserStore>(":memory:"); 20 store->Seed({{"alice"}, {"bob"}}); 21 } 22 23 std::unique_ptr<UserStore> store; 24}; 25 26TEST_F(UserStoreTest, FindsExistingUser) { 27 auto user = store->Find("alice"); 28 ASSERT_TRUE(user.has_value()); 29 EXPECT_EQ(user->name, "alice"); 30}

Mock (gmock)

cpp
1// tests/notifier_test.cpp 2#include <gmock/gmock.h> 3#include <gtest/gtest.h> 4#include <string> 5 6class Notifier { 7public: 8 virtual ~Notifier() = default; 9 virtual void Send(const std::string &message) = 0; 10}; 11 12class MockNotifier : public Notifier { 13public: 14 MOCK_METHOD(void, Send, (const std::string &message), (override)); 15}; 16 17class Service { 18public: 19 explicit Service(Notifier &notifier) : notifier_(notifier) {} 20 void Publish(const std::string &message) { notifier_.Send(message); } 21 22private: 23 Notifier &notifier_; 24}; 25 26TEST(ServiceTest, SendsNotifications) { 27 MockNotifier notifier; 28 Service service(notifier); 29 30 EXPECT_CALL(notifier, Send("hello")).Times(1); 31 service.Publish("hello"); 32}

CMake/CTest Quickstart

cmake
1# CMakeLists.txt (excerpt) 2cmake_minimum_required(VERSION 3.20) 3project(example LANGUAGES CXX) 4 5set(CMAKE_CXX_STANDARD 20) 6set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 8include(FetchContent) 9# Prefer project-locked versions. If using a tag, use a pinned version per project policy. 10set(GTEST_VERSION v1.17.0) # Adjust to project policy. 11FetchContent_Declare( 12 googletest 13 # Google Test framework (official repository) 14 URL https://github.com/google/googletest/archive/refs/tags/${GTEST_VERSION}.zip 15) 16FetchContent_MakeAvailable(googletest) 17 18add_executable(example_tests 19 tests/calculator_test.cpp 20 src/calculator.cpp 21) 22target_link_libraries(example_tests GTest::gtest GTest::gmock GTest::gtest_main) 23 24enable_testing() 25include(GoogleTest) 26gtest_discover_tests(example_tests)
bash
1cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug 2cmake --build build -j 3ctest --test-dir build --output-on-failure

Running Tests

bash
1ctest --test-dir build --output-on-failure 2ctest --test-dir build -R ClampTest 3ctest --test-dir build -R "UserStoreTest.*" --output-on-failure
bash
1./build/example_tests --gtest_filter=ClampTest.* 2./build/example_tests --gtest_filter=UserStoreTest.FindsExistingUser

Debugging Failures

  1. Re-run the single failing test with gtest filter.
  2. Add scoped logging around the failing assertion.
  3. Re-run with sanitizers enabled.
  4. Expand to full suite once the root cause is fixed.

Coverage

Prefer target-level settings instead of global flags.

cmake
1option(ENABLE_COVERAGE "Enable coverage flags" OFF) 2 3if(ENABLE_COVERAGE) 4 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") 5 target_compile_options(example_tests PRIVATE --coverage) 6 target_link_options(example_tests PRIVATE --coverage) 7 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 8 target_compile_options(example_tests PRIVATE -fprofile-instr-generate -fcoverage-mapping) 9 target_link_options(example_tests PRIVATE -fprofile-instr-generate) 10 endif() 11endif()

GCC + gcov + lcov:

bash
1cmake -S . -B build-cov -DENABLE_COVERAGE=ON 2cmake --build build-cov -j 3ctest --test-dir build-cov 4lcov --capture --directory build-cov --output-file coverage.info 5lcov --remove coverage.info '/usr/*' --output-file coverage.info 6genhtml coverage.info --output-directory coverage

Clang + llvm-cov:

bash
1cmake -S . -B build-llvm -DENABLE_COVERAGE=ON -DCMAKE_CXX_COMPILER=clang++ 2cmake --build build-llvm -j 3LLVM_PROFILE_FILE="build-llvm/default.profraw" ctest --test-dir build-llvm 4llvm-profdata merge -sparse build-llvm/default.profraw -o build-llvm/default.profdata 5llvm-cov report build-llvm/example_tests -instr-profile=build-llvm/default.profdata

Sanitizers

cmake
1option(ENABLE_ASAN "Enable AddressSanitizer" OFF) 2option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer" OFF) 3option(ENABLE_TSAN "Enable ThreadSanitizer" OFF) 4 5if(ENABLE_ASAN) 6 add_compile_options(-fsanitize=address -fno-omit-frame-pointer) 7 add_link_options(-fsanitize=address) 8endif() 9if(ENABLE_UBSAN) 10 add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) 11 add_link_options(-fsanitize=undefined) 12endif() 13if(ENABLE_TSAN) 14 add_compile_options(-fsanitize=thread) 15 add_link_options(-fsanitize=thread) 16endif()

Flaky Tests Guardrails

  • Never use sleep for synchronization; use condition variables or latches.
  • Make temp directories unique per test and always clean them.
  • Avoid real time, network, or filesystem dependencies in unit tests.
  • Use deterministic seeds for randomized inputs.

Best Practices

DO

  • Keep tests deterministic and isolated
  • Prefer dependency injection over globals
  • Use ASSERT_* for preconditions, EXPECT_* for multiple checks
  • Separate unit vs integration tests in CTest labels or directories
  • Run sanitizers in CI for memory and race detection

DON'T

  • Don't depend on real time or network in unit tests
  • Don't use sleeps as synchronization when a condition variable can be used
  • Don't over-mock simple value objects
  • Don't use brittle string matching for non-critical logs

Common Pitfalls

  • Using fixed temp paths → Generate unique temp directories per test and clean them.
  • Relying on wall clock time → Inject a clock or use fake time sources.
  • Flaky concurrency tests → Use condition variables/latches and bounded waits.
  • Hidden global state → Reset global state in fixtures or remove globals.
  • Over-mocking → Prefer fakes for stateful behavior and only mock interactions.
  • Missing sanitizer runs → Add ASan/UBSan/TSan builds in CI.
  • Coverage on debug-only builds → Ensure coverage targets use consistent flags.

Optional Appendix: Fuzzing / Property Testing

Only use if the project already supports LLVM/libFuzzer or a property-testing library.

  • libFuzzer: best for pure functions with minimal I/O.
  • RapidCheck: property-based tests to validate invariants.

Minimal libFuzzer harness (pseudocode: replace ParseConfig):

cpp
1#include <cstddef> 2#include <cstdint> 3#include <string> 4 5extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 6 std::string input(reinterpret_cast<const char *>(data), size); 7 // ParseConfig(input); // project function 8 return 0; 9}

Alternatives to GoogleTest

  • Catch2: header-only, expressive matchers
  • doctest: lightweight, minimal compile overhead

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is cpp-testing?

Essential for C++ Development Agents requiring robust test automation and CI/CD integration. Use only when writing/updating/fixing C++ tests, configuring GoogleTest/CTest, diagnosing failing or flaky tests, or adding coverage/sanitizers.

How do I install cpp-testing?

Run the command: npx killer-skills add affaan-m/everything-claude-code/cpp-testing. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for cpp-testing?

Key use cases include: Configuring CMake/CTest workflows for consistent test execution, Diagnosing failing or flaky C++ test behavior, Adding coverage tracking and sanitizers for memory/race diagnostics, Writing and updating unit/integration tests for C++ components.

Which IDEs are compatible with cpp-testing?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for cpp-testing?

C++17/20 specific testing only. Requires GoogleTest/GoogleMock framework. Limited to CMake-based build systems.

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add affaan-m/everything-claude-code/cpp-testing. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use cpp-testing immediately in the current project.

Related Skills

Looking for an alternative to cpp-testing or another official skill for your workflow? Explore these related open-source skills.

View All

flags

Logo of facebook
facebook

Use when you need to check feature flag states, compare channels, or debug why a feature behaves differently across release channels.

243.6k
0
Developer

extract-errors

Logo of facebook
facebook

Use when adding new error messages to React, or seeing unknown error code warnings.

243.6k
0
Developer

fix

Logo of facebook
facebook

Use when you have lint errors, formatting issues, or before committing code to ensure it passes CI.

243.6k
0
Developer

flow

Logo of facebook
facebook

Use when you need to run Flow type checking, or when seeing Flow type errors in React code.

243.6k
0
Developer