mcpField
T
test

test

github.com/parcadei测试与质量3.9k503 次安装39 周前更新
代码仓库

关于 test

test 是用于项目检查的测试工作流技能,适合发布、合并前或代码变更后使用。它并行运行单元和集成测试,只有前序检查通过后才运行 E2E 与验收测试。

主要功能

  1. 01测试前类型诊断
  2. 02并行运行单元与集成测试
  3. 03前序检查通过后运行 E2E
  4. 04完整、功能范围或快速测试
  5. 05覆盖率、监视和跳过选项

适用场景

  1. 01实现功能后检查代码
  2. 02合并或发布前运行测试
  3. 03快速反馈时仅运行单元测试

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/parcadei/continuous-claude-v3 --skill test

安装后在 Claude Code 中输入/test确认已加载。

详细介绍

/test - 测试工作流

并行执行全面的测试套件。

适用场景

  • “运行所有测试”
  • “测试此功能”
  • “验证一切是否正常”
  • “完整测试套件”
  • 发布或合并前
  • 重大更改后

工作流概览

┌─────────────┐      ┌───────────┐
│ diagnostics │ ──▶  │ arbiter  │ ─┐
│ (type check)│      │ (unit)    │  │
└─────────────┘      └───────────┘  │
                                    ├──▶ ┌─────────┐
                     ┌───────────┐  │    │  atlas  │
                     │  arbiter  │ ─┘    │ (e2e)   │
                     │ (integ)   │       └─────────┘
                     └───────────┘

  Pre-flight         Parallel              Sequential
  (~1 second)        fast tests            slow tests

Agent 执行顺序

#Agent角色执行方式
1arbiter单元测试、类型检查、代码检查并行
1arbiter集成测试并行
2atlasE2E/验收测试第 1 阶段通过后

为什么按此顺序?

  1. 快速反馈:单元测试失败得更快
  2. 并行效率:单元测试与集成测试之间没有依赖关系
  3. E2E 门控:只有较快的测试通过后,才运行耗时较长的 E2E 测试

执行

阶段 0:预检诊断(新增)

运行测试前,检查类型错误——它们经常导致测试失败:

tldr diagnostics . --project --format text 2>/dev/null | grep "^E " | head -10

为什么先进行诊断?

  • 类型检查是即时的(约 1 秒),测试则需要更长时间
  • 诊断显示根本原因,测试显示的是症状
  • “预期为 int,实际为 str”比“第 50 行出现 AttributeError”更清晰
  • 可捕获未经测试的代码路径中的错误

**如果发现错误:**请在运行测试前修复。类型错误通常意味着测试无论如何都会失败。

**如果检查通过:**继续阶段 1。

阶段 0.5:更改影响分析(可选)

对于大型测试套件,仅查找受影响的测试:

tldr change-impact --session
# or for explicit files:
tldr change-impact src/changed_file.py

此操作会根据更改内容返回需要运行的测试。小型项目或需要完整覆盖时,可跳过此步骤。

阶段 1:并行测试
# Run both in parallel
Task(
  subagent_type="arbiter",
  prompt="""
  Run unit tests for: [SCOPE]

  Include:
  - Unit tests
  - Type checking
  - Linting

  Report: Pass/fail count, failures detail
  """,
  run_in_background=true
)

Task(
  subagent_type="arbiter",
  prompt="""
  Run integration tests for: [SCOPE]

  Include:
  - Integration tests
  - API tests
  - Database tests

  Report: Pass/fail count, failures detail
  """,
  run_in_background=true
)

# Wait for both
[Check TaskOutput for both]
阶段 2:E2E 测试(阶段 1 通过时)
Task(
  subagent_type="atlas",
  prompt="""
  Run E2E tests for: [SCOPE]

  Include:
  - End-to-end flows
  - Acceptance tests
  - UI tests if applicable

  Report: Pass/fail count, screenshots on failure
  """
)

测试范围

完整套件
User: /test
→ All unit + integration + E2E tests
功能范围
User: /test authentication
→ Only auth-related tests
快速检查
User: /test --quick
→ Only unit tests (skip integration and E2E)

示例

User: /test the new payment feature

Claude: Starting /test workflow for payment feature...

Phase 0: Pre-flight diagnostics...
$ tldr diagnostics . --project --format text | grep "^E "
(no type errors found)

Phase 1: Running parallel tests...
┌─────────────────────────────────────────┐
│ arbiter: Running unit tests...          │
│ arbiter: Running integration tests...   │
└─────────────────────────────────────────┘

arbiter: ✅ 45/45 unit tests passing
arbiter: ✅ 12/12 integration tests passing

Phase 2: Running E2E tests...
atlas: ✅ 8/8 E2E tests passing

Test Summary:
┌─────────────┬─────────┬────────┐
│ Type        │ Passed  │ Failed │
├─────────────┼─────────┼────────┤
│ Unit        │ 45      │ 0      │
│ Integration │ 12      │ 0      │
│ E2E         │ 8       │ 0      │
├─────────────┼─────────┼────────┤
│ TOTAL       │ 65      │ 0      │
└─────────────┴─────────┴────────┘

All tests passing! ✅
类型错误示例
User: /test

Claude: Starting /test workflow...

Phase 0: Pre-flight diagnostics...
$ tldr diagnostics . --project --format text | grep "^E "
E src/payment.py:45:12: Argument of type 'str' not assignable to 'int'
E src/refund.py:23:8: Return type 'None' not assignable to 'float'

Found 2 type errors. Fixing before running tests...

[Claude fixes the type errors]

Re-running diagnostics... clean.

Phase 1: Running parallel tests...

失败处理

如果阶段 1 失败:

arbiter: ❌ 43/45 tests passing

2 failures:
- test_payment_validation: expected 'invalid' got 'valid'
- test_refund_calculation: off by $0.01

Stopping workflow. Fix failures before running E2E tests.

标志

  • --quick:仅运行单元测试
  • --no-e2e:跳过 E2E 测试
  • --coverage:包含覆盖率报告
  • --watch:文件更改时重新运行

评论

支持 Markdown