Back to list
AsiaOstrich

testing-guide

by AsiaOstrich

Universal, language-agnostic development standards for software projects. Includes coding standards, git workflows, testing guidelines, documentation structure, and AI collaboration rules.

20🍴 3📅 Jan 23, 2026

SKILL.md


source: skills/claude-code/testing-guide/SKILL.md source_version: 1.1.0 translation_version: 1.1.0 last_synced: 2025-12-29 status: current name: testing-guide description: | Testing pyramid and test writing standards for UT/IT/ST/E2E. Supports ISTQB and Industry Pyramid frameworks. Use when: writing tests, discussing test coverage, test strategy, or test naming. Keywords: test, unit, integration, e2e, coverage, mock, ISTQB, SIT, 测试, 单元, 集成, 端对端.

测试指南

语言: English | 简体中文

版本: 1.1.0 最後更新: 2025-12-29 適用範圍: Claude Code Skills


目的

本 Skill 提供测试金字塔标准和系统化测试的最佳实踐,支援 ISTQB 和业界通行金字塔框架。

框架选择

框架层级適用場景
ISTQBUT → IT/SIT → ST → AT/UAT企业级、合規性、正式 QA
业界通行金字塔UT (70%) → IT (20%) → E2E (10%)敏捷、DevOps、CI/CD

集成测试縮写说明:

  • IT (Integration Testing):敏捷/DevOps 社群常用
  • SIT (System Integration Testing):企业/ISTQB 環境常用
  • 兩者指的是相同的测试层级

快速參考

测试金字塔(业界标准)

              ┌─────────┐
              │   E2E   │  ← 10%(較少、較慢)
             ─┴─────────┴─
            ┌─────────────┐
            │   IT/SIT    │  ← 20%(集成测试)
           ─┴─────────────┴─
          ┌─────────────────┐
          │       UT        │  ← 70%(单元测试)
          └─────────────────┘

测试层级概覽

层级範圍速度相依性
UT单一函式/类别< 100msMock
IT/SIT元件互动1-10秒真实数据庫(容器化)
ST完整系统(ISTQB)分鐘级类生产環境
E2E使用者旅程30秒+所有真实環境
AT/UAT业务验证(ISTQB)视情况所有真实環境

覆蓋率目標

指標最低要求建议值
行覆蓋率70%85%
分支覆蓋率60%80%
函式覆蓋率80%90%

详细指南

完整标准請參考:

AI 優化格式(Token 高效)

供 AI 助理使用,請採用 YAML 格式文件以減少 Token 使用量:

  • 基礎标准:ai/standards/testing.ai.yaml
  • 框架选项:
    • ISTQB 框架:ai/options/testing/istqb-framework.ai.yaml
    • 业界通行金字塔:ai/options/testing/industry-pyramid.ai.yaml
  • 测试层级选项:
    • 单元测试:ai/options/testing/unit-testing.ai.yaml
    • 集成测试:ai/options/testing/integration-testing.ai.yaml
    • 系统测试:ai/options/testing/system-testing.ai.yaml
    • E2E 测试:ai/options/testing/e2e-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

何时使用

  • UT: 对所有外部相依使用 mock/stub
  • IT: 数据庫使用 fake,外部 API 使用 stub
  • ST: 真实元件,僅对外部服务使用 fake
  • E2E: 全部使用真实環境

AAA 模式

test('method_scenario_expected', () => {
    // Arrange - 设置测试数据
    const input = createTestInput();
    const sut = new SystemUnderTest();

    // Act - 执行行为
    const result = sut.execute(input);

    // Assert - 验证結果
    expect(result).toBe(expected);
});

FIRST 原則

  • Fast(快速) - 测试执行快速
  • Independent(獨立) - 测试之间不互相影響
  • Repeatable(可重複) - 每次执行結果相同
  • Self-validating(自我验证) - 明确的通過/失败
  • Timely(及时) - 与产品代码一起撰写

应避免的反模式

  • ❌ 测试相依(测试必須按順序执行)
  • ❌ 不穩定测试(有时通過、有时失败)
  • ❌ 测试实作細节
  • ❌ 過度 Mock
  • ❌ 缺少斷言
  • ❌ 魔術數字/字串

设置偵测

本 Skill 支援项目特定设置。

偵测順序

  1. 检查 CONTRIBUTING.md 的「停用 Skills」區段
    • 如果列出此 Skill,則为該项目停用
  2. 检查 CONTRIBUTING.md 的「测试标准」區段
  3. 若未找到,预设使用标准覆蓋率目標

首次设置

若未找到设置且上下文不清楚时:

  1. 詢問使用者:「此项目尚未设置测试标准。您想要自订覆蓋率目標嗎?」
  2. 使用者选择後,建议在 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

相关标准


版本历史

版本日期变更内容
1.1.02025-12-29新增:框架选择(ISTQB/业界通行金字塔)、IT/SIT 縮写说明
1.0.02025-12-24新增:标准區段(目的、相关标准、版本历史、授权)

授权

本 Skill 以 CC BY 4.0 授权發布。

來源: universal-dev-standards

Score

Total Score

75/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon