swift-testing-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Swift Testing Code Review

Swift Testing 代码审查

Quick Reference

快速参考

Issue TypeReference
#expect vs #require, expression capture, error testingreferences/expect-macro.md
@Test with arguments, traits, zip() pitfallsreferences/parameterized.md
confirmation, async sequences, completion handlersreferences/async-testing.md
@Suite, tags, parallel execution, .serializedreferences/organization.md
问题类型参考文档
#expect 与 #require、表达式捕获、错误测试references/expect-macro.md
带参数的@Test、特性、zip() 陷阱references/parameterized.md
确认机制、异步序列、完成处理程序references/async-testing.md
@Suite、标签、并行执行、.serializedreferences/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
    confirmation(expectedCount:)
  • Completion handlers use
    withCheckedContinuation
    , not
    confirmation
  • .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
  • 直接在
    #expect
    中嵌入表达式(而非预先计算的布尔值)
  • #require
    仅用于前置条件,
    #expect
    用于断言
  • 错误测试检查特定类型(而非通用的
    (any Error).self
  • 带参数对的参数化测试使用
    zip()
    (而非笛卡尔积)
  • 参数化预期值中没有镜像实现的逻辑
  • 异步序列使用
    confirmation(expectedCount:)
    进行测试
  • 完成处理程序使用
    withCheckedContinuation
    ,而非
    confirmation
  • .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

审查问题

  1. Could pre-computed booleans in
    #expect
    lose diagnostic context?
  2. Is
    #require
    stopping tests prematurely instead of revealing all failures?
  3. Are multi-argument parameterized tests creating accidental Cartesian products?
  4. Could
    zip()
    silently drop test cases due to unequal array lengths?
  5. Are completion handlers incorrectly tested with
    confirmation
    ?
  1. #expect
    中的预先计算布尔值是否会丢失诊断上下文?
  2. #require
    是否过早终止测试,而非暴露所有失败情况?
  3. 多参数参数化测试是否意外生成了笛卡尔积?
  4. zip()
    是否会因数组长度不等而静默丢弃测试用例?
  5. 完成处理程序是否使用了错误的
    confirmation
    进行测试?