swift-testing-code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSwift Testing Code Review
Swift Testing 代码审查
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 |
| 问题类型 | 参考文档 |
|---|---|
| #expect 与 #require、表达式捕获、错误测试 | references/expect-macro.md |
| 带参数的@Test、特性、zip() 陷阱 | references/parameterized.md |
| 确认机制、异步序列、完成处理程序 | references/async-testing.md |
| @Suite、标签、并行执行、.serialized | references/organization.md |
Review Checklist
审查检查清单
- Expressions embedded directly in (not pre-computed booleans)
#expect - used only for preconditions,
#requirefor assertions#expect - Error tests check specific types (not generic )
(any Error).self - Parameterized tests with pairs use (not Cartesian product)
zip() - No logic mirroring implementation in parameterized expected values
- Async sequences tested with
confirmation(expectedCount:) - Completion handlers use , not
withCheckedContinuationconfirmation - applied only where necessary (shared resources)
.serialized - Sibling serialized suites nested under parent if mutually exclusive
- No assumption of state persistence between functions
@Test - Disabled tests have explanations and bug links
- 直接在中嵌入表达式(而非预先计算的布尔值)
#expect - 仅用于前置条件,
#require用于断言#expect - 错误测试检查特定类型(而非通用的)
(any Error).self - 带参数对的参数化测试使用(而非笛卡尔积)
zip() - 参数化预期值中没有镜像实现的逻辑
- 异步序列使用进行测试
confirmation(expectedCount:) - 完成处理程序使用,而非
withCheckedContinuationconfirmation - 仅在必要时应用(如共享资源场景)
.serialized - 互斥的同级序列化套件嵌套在父套件下
- 不假设函数之间的状态会持久化
@Test - 禁用的测试有说明和Bug链接
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
- 审查#expect或#require的使用 -> expect-macro.md
- 审查带参数或特性的@Test -> parameterized.md
- 审查确认机制或异步测试 -> async-testing.md
- 审查@Suite或测试组织方式 -> organization.md
Review Questions
审查问题
- Could pre-computed booleans in lose diagnostic context?
#expect - Is stopping tests prematurely instead of revealing all failures?
#require - Are multi-argument parameterized tests creating accidental Cartesian products?
- Could silently drop test cases due to unequal array lengths?
zip() - Are completion handlers incorrectly tested with ?
confirmation
- 中的预先计算布尔值是否会丢失诊断上下文?
#expect - 是否过早终止测试,而非暴露所有失败情况?
#require - 多参数参数化测试是否意外生成了笛卡尔积?
- 是否会因数组长度不等而静默丢弃测试用例?
zip() - 完成处理程序是否使用了错误的进行测试?
confirmation