Swift Testing Code Review
Quick Reference
| Issue Type | Reference |
|---|
| #expect vs #require, expression capture, error testing | references/expect-macro.md |
| @Test with arguments, traits, zip() pitfalls |
references/parameterized.md |
| confirmation, async sequences, completion handlers |
references/async-testing.md |
| @Suite, tags, parallel execution, .serialized |
references/organization.md |
Review Checklist
- - [ ] Expressions embedded directly in
#expect (not pre-computed booleans) - [ ]
#require used only for preconditions, #expect for assertions - [ ] Error tests check specific types (not generic
(any Error).self) - [ ] Parameterized tests with pairs use
zip() (not Cartesian product) - [ ] No logic mirroring implementation in parameterized expected values
- [ ] Async sequences tested with INLINECODE5
- [ ] Completion handlers use
withCheckedContinuation, not INLINECODE7 - [ ]
.serialized applied only where necessary (shared resources) - [ ] Sibling serialized suites nested under parent if mutually exclusive
- [ ] No assumption of state persistence between
@Test functions - [ ] Disabled tests have explanations and bug links
When to Load References
- - Reviewing #expect or #require usage -> expect-macro.md
- Reviewing @Test with arguments or traits -> parameterized.md
- Reviewing confirmation or async testing -> async-testing.md
- Reviewing @Suite or test organization -> organization.md
Review Questions
- 1. Could pre-computed booleans in
#expect lose diagnostic context? - Is
#require stopping tests prematurely instead of revealing all failures? - Are multi-argument parameterized tests creating accidental Cartesian products?
- Could
zip() silently drop test cases due to unequal array lengths? - Are completion handlers incorrectly tested with
confirmation?
Swift 测试代码审查
快速参考
references/parameterized.md |
| confirmation、异步序列、完成处理器 |
references/async-testing.md |
| @Suite、标签、并行执行、.serialized |
references/organization.md |
审查清单
- - [ ] 表达式直接嵌入在 #expect 中(而非预先计算的布尔值)
- [ ] #require 仅用于前置条件,#expect 用于断言
- [ ] 错误测试检查特定类型(而非泛型 (any Error).self)
- [ ] 使用 zip() 的参数化测试对(而非笛卡尔积)
- [ ] 参数化预期值中不包含镜像实现的逻辑
- [ ] 使用 confirmation(expectedCount:) 测试异步序列
- [ ] 完成处理器使用 withCheckedContinuation,而非 confirmation
- [ ] 仅在必要时应用 .serialized(共享资源)
- [ ] 互斥的兄弟序列化套件嵌套在父套件下
- [ ] 不假设 @Test 函数之间的状态持久性
- [ ] 禁用的测试附有说明和 Bug 链接
何时加载参考文档
- - 审查 #expect 或 #require 用法 -> expect-macro.md
- 审查带参数或特性的 @Test -> parameterized.md
- 审查 confirmation 或异步测试 -> async-testing.md
- 审查 @Suite 或测试组织 -> organization.md
审查问题
- 1. #expect 中的预计算布尔值是否会丢失诊断上下文?
- #require 是否过早停止测试,而非揭示所有失败?
- 多参数参数化测试是否意外产生了笛卡尔积?
- zip() 是否会因数组长度不相等而静默丢弃测试用例?
- 完成处理器是否被错误地使用 confirmation 进行测试?