Cpp Testing

仅在编写/更新/修复 C++ 测试、配置 GoogleTest/CTest、诊断失败或不稳定的测试、或添加覆盖率/检测器(Sanitizers)时使用。

2,037 stars 332 forksTesting & QA Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add xu-xiang/everything-claude-code-zh

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add xu-xiang/everything-claude-code-zh --skill cpp-testing
Manual install
git clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git /tmp/everything-claude-code-zh
mkdir -p ~/.claude/skills
cp -r /tmp/everything-claude-code-zh/skills/cpp-testing ~/.claude/skills/cpp-testing

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# C++ 测试(智能体技能)

针对现代 C++ (C++17/20) 的智能体测试工作流,使用 GoogleTest/GoogleMock 配合 CMake/CTest。

## 适用场景

- 编写新的 C++ 测试或修复现有测试
- 为 C++ 组件设计单元/集成测试覆盖
- 添加测试覆盖、CI 门禁或回归防护
- 配置 CMake/CTest 工作流以实现一致性执行
- 调查测试失败或不稳定(Flaky)行为
- 启用检测器(Sanitizers)进行内存/竞态诊断

### 不适用场景

- 实施不涉及测试更改的新产品功能
- 与测试覆盖或失败无关的大规模重构
- 在没有测试回归验证的情况下进行性能调优
- 非 C++ 项目或非测试任务

## 核心概念

- **TDD 循环**:红(Red)→ 绿(Green)→ 重构(Refactor)(测试先行,最小化修复,然后清理)。
- **隔离性**:优先选择依赖注入和伪造对象(Fakes),而非全局状态。
- **测试布局**:`tests/unit`、`tests/integration`、`tests/testdata`。
- **Mocks vs Fakes**:Mock 用于交互验证,Fake 用于有状态的行为模拟。
- **CTest 发现**:使用 `gtest_discover_tests()` 进行稳定的测试发现。
- **CI 信号**:先运行子集,然后使用 `--output-on-failure` 运行完整套件。

## TDD 工作流

遵循 红 → 绿 → 重构 循环:

1. **红(RED)**:编写一个捕获新行为的失败测试。
2. **绿(GREEN)**:实施最小化的更改以使测试通过。
3. **重构(REFACTOR)**:在保持测试为绿色的前提下进行清理。

```cpp
// tests/add_test.cpp
#include <gtest/gtest.h>

int Add(int a, int b); // 由生产代码提供。

TEST(AddTest, AddsTwoNumbers) { // 红(RED)
  EXPECT_EQ(Add(2, 3), 5);
}

// src/add.cpp
int Add(int a, int b) { // 绿(GREEN)
  return a + b;
}

// 重构(REFACTOR):一旦测试通过,简化/重命名代码
```

## 代码示例

### 基础单元测试 (gtest)

```cpp
// tests/calculator_test.cpp
#include <gtest/gtest.h>

int Add(int a, int b); // 由生产代码提供。

TEST(CalculatorTest, AddsTwoNumbers) {
    EXPECT_EQ(Add(2, 3), 5);
}
```

### 测试固件 (Fixture) (gtest)
Read the full skill on GitHub

Details

Skill name
cpp-testing
Path
skills/cpp-testing/SKILL.md
License
MIT
Repo updated
5 March 2026

FAQ

What does the Cpp Testing skill do?

仅在编写/更新/修复 C++ 测试、配置 GoogleTest/CTest、诊断失败或不稳定的测试、或添加覆盖率/检测器(Sanitizers)时使用。

How do I install the Cpp Testing skill?

Claude Code plugin: /plugin marketplace add xu-xiang/everything-claude-code-zh. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Cpp Testing popular?

It lives in xu-xiang/everything-claude-code-zh, which has 2,037 GitHub stars and 332 forks.

Related skills

Browse the most popular Claude skills, all testing & qa skills, or write your own with the skills generator.