cpp-testing
Use only when writing/updating/fixing C++ tests, configuring GoogleTest/CTest, diagnosing failing or flaky tests, or adding coverage/sanitizers.
Machine translationRead the original Chinese text
仅用于编写/更新/修复C++测试、配置GoogleTest/CTest、诊断失败或不稳定的测试,或添加覆盖率/消毒器时使用。
Target: Software development & testing. Automatically collected · unverified.
Excerpt from the author’s documentation
Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.
Read the original Chinese text
Topics in the source
- C++ 测试(代理技能)
- 使用时机
- 不适用时机
- 核心概念
- TDD 工作流
- 代码示例
- 基础单元测试 (gtest)
- 夹具 (gtest)
针对现代 C++(C++17/20)的代理导向测试工作流,使用 GoogleTest/GoogleMock 和 CMake/CTest。 编写新的 C++ 测试或修复现有测试 为 C++ 组件设计单元/集成测试覆盖 添加测试覆盖、CI 门控或回归保护 配置 CMake/CTest 工作流以实现一致的执行 调查测试失败或偶发性行为 启用用于内存/竞态诊断的消毒剂 在不修改测试的情况下实现新的产品功能 与测试覆盖或失败无关的大规模重构 没有测试回归需要验证的性能调优 非 C++ 项目或非测试任务 TDD 循环:红 → 绿 → 重构(先写测试,最小化修复,然后清理)。 隔离:优先使用依赖注入和仿制品,而非全局状态。 测试布局:tests/unit、tests/integration、tests/testdata。 Mock 与 Fake:Mock 用于交互,Fake 用于有状态行为。 CTest 发现:使用 gtestdiscovertests() 进行稳定的测试发现。 CI 信号:先运行子集,然后使用 --output-on-failure 运行完整套件。 遵循 RED → GREEN → REFACTOR 循环: 1. RED:编写一个捕获新行为的失败测试 2. GREEN:实现最小的更改以使其通过 3. REFACTOR:在测试保持通过的同时进行清理 1. 使用 gtest 过滤器重新运行单个失败的测试。 2. 在失败的断言周围添加作用域日志记录。 3. 启用消毒剂后重新运行。 4. 根本原因修复后,扩展到完整套件。 优先使用目标级别的设置,而非全局标志。 GCC + gcov + lcov: Clang + llvm-cov: 切勿使用 sleep 进行同步;使用条件变量或门闩。 为每个测试创建唯一的临时目录并始终清理它们。 避免在单元测试中依赖真实时间、网络或文件系统。 对随机化输入使用确定性种子。 保持测试的确定性和隔离性 优先使用依赖注入而非全局变量 对前置条件使用 ASSERT,对多个检查使用 EXPECT 在 CTest 标签或目录中分离单元测试与集成测试 在 CI 中运行消毒剂以进行内存和竞态检测 不要在单元测试中依赖真实时间或网络 当可以使用条件变量时,不要使用睡眠作为同步手段 不要过度模拟简单的值对象 不要对非关键日志使用脆弱的字符串匹配 使用固定的临时路径 → 为每个测试生成唯一的临时目录并清理它们。 依赖挂钟时间 → 注入时钟或使用模拟时间源。 偶发性并发测试 → 使用条件变量/门闩和有界等待。 隐藏的全局状态 → 在夹具中重置全局状态或移除全局变量。 过度模拟 → 对有状态行为优先使用 Fake,仅对交互进行 Mock。 缺少消毒剂运行 → 在 CI 中添加 ASan/UBSan/TSan 构建。 仅在调试版本上计算覆盖率 → 确保覆
This is an excerpt. Refer to the complete source and its current requirements.
- Source repository
- affaan-m/ECC
- Source file
- docs/zh-CN/skills/cpp-testing/SKILL.md
- Fixed revision
- d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Requirements
- Only the author’s Skill metadata is included. Read the full instructions to check dependencies, licensing and conditions of use.
A small first task
先阅读原作者说明,再决定是否在自己的 AI 工具中使用。
Instructions for your AI tool
- Claude Desktop: resource-specific guide not available yet
- Claude Code: resource-specific guide not available yet
- Cursor: resource-specific guide not available yet
- Codex: resource-specific guide not available yet
Author documentation is not live verification by this site. Without evidence, we do not mark a resource as compatible, safe or free.
Sources and evidence
This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.
Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T14:01:50.270Z.
Categories are inferred from names, descriptions and paths. They do not establish compatibility.
License and attribution
MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.
Original license ↗Synchronization, copying and user-reported success do not mark a resource as runtime-tested.
Limitations and notes
- Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.