test
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/test - Testing Workflow
/test - 测试工作流
Run comprehensive test suite with parallel execution.
运行包含并行执行的全面测试套件。
When to Use
适用场景
- "Run all tests"
- "Test the feature"
- "Verify everything works"
- "Full test suite"
- Before releases or merges
- After major changes
- 「运行所有测试」
- 「测试功能」
- 「验证所有功能正常」
- 「完整测试套件」
- 发布或合并之前
- 重大变更之后
Workflow Overview
工作流概述
┌─────────────┐ ┌───────────┐
│ diagnostics │ ──▶ │ arbiter │ ─┐
│ (type check)│ │ (unit) │ │
└─────────────┘ └───────────┘ │
├──▶ ┌─────────┐
┌───────────┐ │ │ atlas │
│ arbiter │ ─┘ │ (e2e) │
│ (integ) │ └─────────┘
└───────────┘
Pre-flight Parallel Sequential
(~1 second) fast tests slow tests┌─────────────┐ ┌───────────┐
│ diagnostics │ ──▶ │ arbiter │ ─┐
│ (type check)│ │ (unit) │ │
└─────────────┘ └───────────┘ │
├──▶ ┌─────────┐
┌───────────┐ │ │ atlas │
│ arbiter │ ─┘ │ (e2e) │
│ (integ) │ └─────────┘
预检(约1秒) 并行快速测试 串行慢测试Agent Sequence
Agent 执行序列
| # | Agent | Role | Execution |
|---|---|---|---|
| 1 | arbiter | Unit tests, type checks, linting | Parallel |
| 1 | arbiter | Integration tests | Parallel |
| 2 | atlas | E2E/acceptance tests | After 1 passes |
| 序号 | Agent | 职责 | 执行方式 |
|---|---|---|---|
| 1 | arbiter | 单元测试、类型检查、代码扫描 | 并行 |
| 1 | arbiter | 集成测试 | 并行 |
| 2 | atlas | E2E/验收测试 | 待步骤1通过后执行 |
Why This Order?
为何采用此顺序?
- Fast feedback: Unit tests fail fast
- Parallel efficiency: No dependency between unit and integration
- E2E gating: Only run slow E2E tests if faster tests pass
- 快速反馈:单元测试可快速暴露问题
- 并行效率:单元测试与集成测试之间无依赖
- E2E 把关:仅当快速测试通过后才运行耗时的E2E测试
Execution
执行流程
Phase 0: Pre-flight Diagnostics (NEW)
阶段0:预检诊断(新增)
Before running tests, check for type errors - they often cause test failures:
bash
tldr diagnostics . --project --format text 2>/dev/null | grep "^E " | head -10Why diagnostics first?
- Type check is instant (~1s), tests take longer
- Diagnostics show ROOT CAUSE, tests show symptoms
- "Expected int, got str" is clearer than "AttributeError at line 50"
- Catches errors in untested code paths
If errors found: Fix them BEFORE running tests. Type errors usually mean tests will fail anyway.
If clean: Proceed to Phase 1.
在运行测试前,先检查类型错误——这类错误通常会导致测试失败:
bash
tldr diagnostics . --project --format text 2>/dev/null | grep "^E " | head -10为何先做诊断?
- 类型检查耗时极短(约1秒),而测试耗时更长
- 诊断可显示问题根源,测试仅能显示症状
- 「预期int类型,实际传入str类型」比「第50行出现AttributeError」更清晰
- 可捕获未测试代码路径中的错误
若发现错误: 在运行测试前修复这些问题。类型错误通常意味着测试大概率会失败。
若检查通过: 进入阶段1。
Phase 0.5: Change Impact (Optional)
阶段0.5:变更影响(可选)
For large test suites, find only affected tests:
bash
tldr change-impact --session对于大型测试套件,可仅运行受影响的测试:
bash
tldr change-impact --sessionor for explicit files:
或指定文件:
tldr change-impact src/changed_file.py
This returns which tests to run based on what changed. Skip this for small projects or when you want full coverage.tldr change-impact src/changed_file.py
该命令会根据变更内容返回需要运行的测试。小型项目或需要全量覆盖时可跳过此步骤。Phase 1: Parallel Tests
阶段1:并行测试
undefinedundefinedRun 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
)
Task(
subagent_type="arbiter",
prompt="""
运行以下范围的单元测试:[SCOPE]
包含:
- 单元测试
- 类型检查
- 代码扫描
报告:通过/失败数量、失败详情
""",
run_in_background=true
)
Task(
subagent_type="arbiter",
prompt="""
运行以下范围的集成测试:[SCOPE]
包含:
- 集成测试
- API测试
- 数据库测试
报告:通过/失败数量、失败详情
""",
run_in_background=true
)
Wait for both
等待两者完成
[Check TaskOutput for both]
undefined[检查两个任务的输出]
undefinedPhase 2: E2E Tests (If Phase 1 Passes)
阶段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
"""
)Task(
subagent_type="atlas",
prompt="""
运行以下范围的E2E测试:[SCOPE]
包含:
- 端到端流程
- 验收测试
- 适用时包含UI测试
报告:通过/失败数量、失败时截图
"""
)Test Scopes
测试范围
Full Suite
完整套件
User: /test
→ All unit + integration + E2E tests用户:/test
→ 所有单元测试+集成测试+E2E测试Feature Scope
功能范围
User: /test authentication
→ Only auth-related tests用户:/test authentication
→ 仅运行与认证相关的测试Quick Check
快速检查
User: /test --quick
→ Only unit tests (skip integration and E2E)用户:/test --quick
→ 仅运行单元测试(跳过集成测试和E2E测试)Example
示例
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! ✅用户:/test the new payment feature
Claude:启动支付功能的/test工作流...
阶段0:执行预检诊断...
$ tldr diagnostics . --project --format text | grep "^E "
(未发现类型错误)
阶段1:运行并行测试...
┌─────────────────────────────────────────┐
│ arbiter:正在运行单元测试... │
│ arbiter:正在运行集成测试... │
└─────────────────────────────────────────┘
arbiter:✅ 45/45 单元测试通过
arbiter:✅ 12/12 集成测试通过
阶段2:运行E2E测试...
atlas:✅ 8/8 E2E测试通过
测试汇总:
┌─────────────┬─────────┬────────┐
│ 类型 │ 通过数 │ 失败数 │
├─────────────┼─────────┼────────┤
│ 单元测试 │ 45 │ 0 │
│ 集成测试 │ 12 │ 0 │
│ E2E测试 │ 8 │ 0 │
├─────────────┼─────────┼────────┤
│ 总计 │ 65 │ 0 │
└─────────────┴─────────┴────────┘
所有测试通过!✅Example with Type Errors
存在类型错误的示例
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...用户:/test
Claude:启动/test工作流...
阶段0:执行预检诊断...
$ tldr diagnostics . --project --format text | grep "^E "
E src/payment.py:45:12: 参数类型'str'无法赋值给'int'
E src/refund.py:23:8: 返回类型'None'无法赋值给'float'
发现2处类型错误,先修复再运行测试...
[Claude修复类型错误]
重新执行诊断... 检查通过。
阶段1:运行并行测试...Failure Handling
失败处理
If Phase 1 fails:
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.若阶段1失败:
arbiter:❌ 43/45 测试通过
2处失败:
- test_payment_validation:预期'invalid',实际得到'valid'
- test_refund_calculation:差值为$0.01
终止工作流。修复失败后再运行E2E测试。Flags
标记
- : Unit tests only
--quick - : Skip E2E tests
--no-e2e - : Include coverage report
--coverage - : Re-run on file changes
--watch
- :仅运行单元测试
--quick - :跳过E2E测试
--no-e2e - :包含覆盖率报告
--coverage - :文件变更时重新运行测试
--watch