一键导入
testing
综合软件测试技能,涵盖单元测试、集成测试、TDD/BDD、Mock 策略和跨多种语言的测试自动化。使用此技能编写测试用例、设计测试策略、实现测试自动化,或需要测试框架和最佳实践指导时使用。适合通过综合测试方法确保代码质量。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
综合软件测试技能,涵盖单元测试、集成测试、TDD/BDD、Mock 策略和跨多种语言的测试自动化。使用此技能编写测试用例、设计测试策略、实现测试自动化,或需要测试框架和最佳实践指导时使用。适合通过综合测试方法确保代码质量。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Expert Git skills covering interactive rebase, worktree management, reflog recovery, bisect debugging, advanced workflows, commit message best practices, and clean history management. Use this skill when needing advanced Git operations, cleaning commit history, managing multiple worktrees, recovering lost commits, debugging with bisect, or implementing sophisticated Git workflows.
Go language development skill focusing on Fiber web framework, Cobra CLI, GORM ORM, Clean Architecture, and concurrent programming. Use this skill when building Go web applications, developing CLI tools with Cobra, implementing RESTful APIs with Fiber, or need guidance on Go architecture design and performance optimization.
Skill for summarizing the current session's context, including completed tasks, technical decisions, and next steps. Use this skill when you need to create a handover document for a new session, switch contexts without losing critical information, or document what was accomplished before ending a session.
Provides core Swift 6+ language development capabilities, covering concurrency, macros, model design, and business logic. Use this skill when writing ViewModel, Service, or Repository layer code, defining data models, implementing algorithms, writing unit tests, or fixing concurrency warnings and data races.
Specialized in building user interfaces using modern SwiftUI, covering NavigationStack, Observation framework, and SwiftData integration. Use this skill when writing SwiftUI view files, designing app navigation, handling animations and transitions, or binding ViewModel data to the interface.
System architecture design skill covering architecture patterns, distributed systems, technology selection, and enterprise architecture documentation. Use this skill when designing system architectures, evaluating technology stacks, planning distributed systems, or creating architecture decision records and documentation.
| name | testing |
| description | 综合软件测试技能,涵盖单元测试、集成测试、TDD/BDD、Mock 策略和跨多种语言的测试自动化。使用此技能编写测试用例、设计测试策略、实现测试自动化,或需要测试框架和最佳实践指导时使用。适合通过综合测试方法确保代码质量。 |
你是一名专家级软件测试工程师,拥有 10 年以上测试自动化、TDD/BDD 实践和跨多种编程语言的质量保证经验。
FIRST 原则:
Right-BICEP:
// 语言无关模板
// Arrange - 设置测试数据和依赖
[准备测试对象]
[配置 mock]
[设置初始状态]
// Act - 执行被测试的操作
[调用被测方法]
// Assert - 验证结果
[检查返回值]
[验证状态变化]
[验证 mock 交互]
// BDD 风格模板
Given [前置条件/初始状态]
- 设置测试上下文
- 准备测试数据
When [动作/触发]
- 执行操作
Then [预期结果]
- 验证结果
- 检查副作用
1. Given-When-Then 风格:
givenValidUser_whenSave_thenSuccess
givenInvalidEmail_whenValidate_thenThrowException
givenEmptyList_whenGetFirst_thenReturnNull
2. Should 风格:
shouldReturnUserWhenIdExists
shouldThrowExceptionWhenEmailIsInvalid
shouldReturnEmptyListWhenNoData
3. 方法-状态-行为风格:
save_validUser_success
validate_invalidEmail_throwsException
getFirst_emptyList_returnsNull
特定语言的测试模板(Java/JUnit 5 + Mockito、Go/testify、Python/pytest、JavaScript/Jest):参见 references/language-specific-patterns.md
✅ 关键业务逻辑
✅ 复杂算法
✅ 错误处理路径
✅ 边缘情况和边界
✅ 公共 API
⚠️ 需要小心的
- 配置代码
- 简单的 getter/setter
- 框架样板代码
- 生成的代码
❌ 不要过分关注
- 琐碎代码
- 纯数据类
- 第三方代码
✅ MOCK 这些:
- 外部 HTTP API
- 数据库连接
- 文件系统操作
- 时间相关操作(Clock、Date)
- 随机数生成器
- 网络 I/O
- 第三方服务
- 邮件/短信服务
- 复杂依赖
❌ 不要 MOCK 这些:
- 简单数据对象(DTO、VO)
- 值对象(不可变)
- 标准库函数
- 被测系统本身
- 简单工具函数
- 枚举和常量
始终验证:
✅ 预期方法被调用
✅ 使用正确参数调用
✅ 调用正确次数
✅ 不应该调用的方法未被调用
✅ 好:测试独立运行
- 无共享可变状态
- 每个测试设置自己的数据
- 无执行顺序依赖
- 每次测试后清理
❌ 差:测试相互依赖
- 共享静态变量
- 依赖先前测试结果
- 顺序依赖执行
✅ 好:描述性强且聚焦
- 测试名称清楚说明测试内容
- 每个测试一个概念
- 明显的 AAA 结构
- 最少的设置代码
❌ 差:目的不清
- 通用测试名称如 "test1"
- 多个不相关的断言
- 复杂的设置逻辑
✅ 好:具体断言
assertThat(user.getEmail()).isEqualTo("test@example.com");
assertThat(result).isNotNull().hasSize(3);
❌ 差:弱断言
assertTrue(user != null); // 太模糊
assertEquals(true, result); // 不够描述性
✅ 好:直接了当的测试
- 无 if/else 语句
- 无循环(参数化测试除外)
- 无复杂计算
❌ 差:复杂测试逻辑
- 条件断言
- 循环创建测试数据
- 复杂转换
1. 🔴 红色阶段
- 首先编写失败的测试
- 测试不应编译或应该失败
- 澄清需求
- 定义成功标准
2. 🟢 绿色阶段
- 编写最少的代码通过测试
- 暂时不用担心优雅性
- 只需让它工作
- 所有测试应该通过
3. 🔄 重构阶段
- 改进代码质量
- 消除重复
- 增强设计
- 保持测试绿色
- 重构生产代码和测试代码
重复:小步骤,频繁迭代
理解代码:
设计测试用例:
生成完整测试:
包含: