locales/zh-CN/skills/testing-guide/SKILL.md
面向 UT/IT/ST/E2E 的测试金字塔与测试编写标准。 支持 ISTQB 与业界通行金字塔两种框架。 使用时机:编写测试、讨论测试覆盖率、测试策略或测试命名时。 关键词:test, unit, integration, e2e, coverage, mock, ISTQB, SIT, 测试, 单元, 集成, 端对端。
npx skillsauth add asiaostrich/universal-dev-standards testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
语言: English | 简体中文
版本: 1.2.0 最后更新: 2026-01-29 适用范围: Claude Code Skills
本 Skill 提供测试金字塔标准和系统化测试的最佳实践,同时支持 ISTQB 与业界通行金字塔两种框架。
UDS 提供 6 个与测试相关的 Skill。使用以下决策树找到合适的那一个:
你想做什么? | What do you want to do?
├── 测量代码覆盖率(行/分支/函数) → /coverage
├── 追踪哪些需求已有测试(AC 可追溯性) → /ac-coverage
├── 以测试驱动开发进行(红-绿-重构) → /tdd
├── 编写 BDD 场景(Given-When-Then) → /bdd
├── 与利益相关者定义验收测试 → /atdd
└── 学习测试标准与最佳实践 → /testing(本 Skill)
| Skill | 焦点 | Focus |
|-------|------|-------|
| /testing | 测试标准与最佳实践参考 | Standards and best practices reference |
| /coverage | 代码层级覆盖率分析 | Code-level coverage analysis |
| /ac-coverage | 需求层级 AC 可追溯性 | Requirement-level AC traceability |
| /tdd | 红-绿-重构开发循环 | Red-Green-Refactor development cycle |
| /bdd | Given-When-Then 行为场景 | Behavior scenarios with Given-When-Then |
| /atdd | 与利益相关者定义验收条件 | Acceptance criteria with stakeholders |
| 框架 | 层级 | 适用场景 | |-----------|--------|----------| | ISTQB | UT → IT/SIT → ST → AT/UAT | 企业级、合规性、正式 QA | | 业界通行金字塔 | UT (70%) → IT (20%) → E2E (10%) | 敏捷、DevOps、CI/CD |
集成测试缩写说明:
┌─────────┐
│ E2E │ ← 10%(较少、较慢)
─┴─────────┴─
┌─────────────┐
│ IT/SIT │ ← 20%(集成测试)
─┴─────────────┴─
┌─────────────────┐
│ UT │ ← 70%(单元测试)
└─────────────────┘
| 层级 | 范围 | 速度 | 依赖 | |-------|-------|-------|-------------| | UT | 单一函数/类 | < 100ms | Mock | | IT/SIT | 组件交互 | 1-10秒 | 真实数据库(容器化) | | ST | 完整系统(ISTQB) | 分钟级 | 类生产环境 | | E2E | 用户旅程 | 30秒+ | 一切均为真实 | | AT/UAT | 业务验证(ISTQB) | 视情况 | 一切均为真实 |
| 指标 | 最低要求 | 建议值 | |--------|---------|-------------| | 行覆盖率 | 70% | 85% | | 分支覆盖率 | 60% | 80% | | 函数覆盖率 | 80% | 90% |
完整标准请参考:
供 AI 助理使用,请采用 YAML 格式文件以减少 Token 用量:
ai/standards/testing.ai.yamlai/options/testing/istqb-framework.ai.yamlai/options/testing/industry-pyramid.ai.yamlai/options/testing/unit-testing.ai.yamlai/options/testing/integration-testing.ai.yamlai/options/testing/system-testing.ai.yamlai/options/testing/e2e-testing.ai.yamlai/options/testing/security-testing.ai.yamlai/options/testing/performance-testing.ai.yamlai/options/testing/contract-testing.ai.yaml[ClassName]Tests.cs # C#
[ClassName].test.ts # TypeScript
[class_name]_test.py # Python
[class_name]_test.go # Go
[MethodName]_[Scenario]_[ExpectedResult]()
should_[behavior]_when_[condition]()
test_[method]_[scenario]_[expected]()
| 类型 | 用途 | 使用时机 | |------|---------|-------------| | Stub | 返回预定义值 | 固定的 API 响应 | | Mock | 验证交互 | 检查方法是否被调用 | | Fake | 简化实现 | 内存数据库 | | Spy | 记录调用、委派 | 部分 Mock |
test('method_scenario_expected', () => {
// Arrange - Setup test data
const input = createTestInput();
const sut = new SystemUnderTest();
// Act - Execute behavior
const result = sut.execute(input);
// Assert - Verify result
expect(result).toBe(expected);
});
# === ISTQB FUNDAMENTALS ===
terminology:
error: "Human mistake in thinking"
defect: "Bug in code (caused by error)"
failure: "System behaves incorrectly (caused by defect)"
chain: "Error → Defect → Failure"
oracle_problem:
definition: "How do we know the expected result is correct?"
approaches:
- specification_oracle: "Compare against spec"
- reference_oracle: "Compare against reference impl"
- consistency_oracle: "Same input → same output"
- heuristic_oracle: "Reasonable approximation"
# === STATIC vs DYNAMIC ===
static_testing:
definition: "Examine without executing"
techniques: [reviews, walkthroughs, inspections, static_analysis]
finds: "Defects before runtime"
examples: [ESLint, SonarQube, code_review]
dynamic_testing:
definition: "Execute and observe behavior"
techniques: [unit, integration, system, acceptance]
finds: "Failures during execution"
# === TEST DESIGN TECHNIQUES ===
black_box:
equivalence_partitioning:
principle: "Divide inputs into equivalent classes"
example: "Age: [<0 invalid], [0-17 minor], [18-64 adult], [65+ senior]"
boundary_value:
principle: "Test at boundaries of partitions"
example: "Age: test -1, 0, 17, 18, 64, 65"
decision_table:
principle: "Combinations of conditions → actions"
use: "Complex business rules"
state_transition:
principle: "Valid sequences of states"
use: "Workflow, state machines"
white_box:
statement_coverage: "Every statement executed once"
branch_coverage: "Every decision branch taken"
condition_coverage: "Every condition T/F"
path_coverage: "Every possible path (often impractical)"
# === RISK-BASED TESTING ===
risk_assessment:
likelihood: "How likely to fail?"
impact: "How bad if fails?"
priority: "likelihood × impact"
risk_matrix:
high_high: "Test extensively, first priority"
high_low: "Good coverage"
low_high: "Good coverage"
low_low: "Basic coverage"
# === DEFECT MANAGEMENT ===
defect_lifecycle:
states: [new, assigned, in_progress, fixed, verified, closed]
reopen_trigger: "Verification fails"
severity_vs_priority:
severity: "Technical impact (critical/major/minor/trivial)"
priority: "Business urgency (high/medium/low)"
example: "Typo on login page: low severity, high priority (brand)"
# === TEST ENVIRONMENT ===
isolation_levels:
unit: "In-memory, mocked deps"
integration: "Containerized DB (Docker)"
staging: "Production-like, isolated"
production: "Real, feature flags for testing"
test_data_strategies:
fixtures: "Static predefined data"
factories: "Dynamic generation (faker)"
snapshots: "Sanitized production copy"
synthetic: "Algorithm-generated edge cases"
本 Skill 支持项目特定的设置。
CONTRIBUTING.md 的「Disabled Skills」(停用 Skills)区段
CONTRIBUTING.md 的「Testing Standards」(测试标准)区段若未找到设置且上下文不清楚时:
CONTRIBUTING.md 中记录:## Testing Standards
### Coverage Targets
| Metric | Target |
|--------|--------|
| Line | 80% |
| Branch | 70% |
| Function | 85% |
在项目的 CONTRIBUTING.md 中:
## Testing Standards
### Coverage Targets
| Metric | Target |
|--------|--------|
| Line | 80% |
| Branch | 70% |
| Function | 85% |
### Testing Framework
- Unit Tests: Jest
- Integration Tests: Supertest
- E2E Tests: Playwright
/testing 完成后,AI 助理应建议:
测试标准与最佳实践已掌握。建议下一步 / Testing standards and best practices understood. Suggested next steps:
- 执行
/tdd开始测试驱动开发(红-绿-重构循环) ⭐ 推荐 / Recommended — 将测试知识立即转化为实践 / Turn testing knowledge into practice immediately- 执行
/coverage分析当前代码覆盖率 — 找出测试缺口 / Identify testing gaps- 执行
/bdd编写行为驱动的 Given-When-Then 场景 — 从用户角度定义测试 / Define tests from user perspective
| 版本 | 日期 | 变更内容 | |---------|------|---------| | 1.2.0 | 2026-01-29 | 新增指向新建 testing-theory.md 知识库的链接 | | 1.1.0 | 2025-12-29 | 新增测试理论要点 YAML 区段 | | 1.0.0 | 2025-12-24 | 初版:标准区段(目的、相关标准、版本历史、授权) |
本 Skill 以 CC BY 4.0 授权发布。
来源: universal-dev-standards
development
[UDS] 扫描代码库的调试残留与代码质量问题;可自动修正安全模式。 Use when: before committing, during PR review, or periodic codebase cleanup. Keywords: sweep, debug cleanup, console.log, debugger, TODO, ts-any, code quality, 扫描, 清理.
tools
[UDS] 从规格衍生 BDD 场景、TDD 骨架或 ATDD 表格
development
[UDS] 识别重复流程并以正确的开发深度构建 Skill
tools
[UDS] AI 辅助 git push 安全层:质量门禁 + 协作护栏。 Use when: pushing commits, force pushing, pushing to protected branches, pushing feature branches. Keywords: git push, force push, protected branch, quality gate, push receipt, PR automation, 推送, 保护分支, 质量门禁.