cmux-testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesecmux Testing
cmux测试
Test framework
测试框架
Swift Testing is the current Apple-supported primitive for tests on this codebase (shipped with Swift 6 / Xcode 16, supported on the macOS versions we target). Use it for everything that is not a UI test.
- Default to Swift Testing for all unit and integration tests. , annotate tests with
import Testing, group with@Test, assert with@Suiteand#expect(...). Do not write new tests withtry #require(...)unless they are UI tests.import XCTest - UI tests stay on XCTest / XCUITest. Swift Testing does not support UI testing (no integration). Files under
XCUIApplicationcontinue to usecmuxUITests/+XCTestCase. Do not migrate them and do not try to bridge Swift Testing into UI tests.XCUIApplication - New test targets start on Swift Testing. Every new Swift package's directory (e.g.
Tests/<Name>Tests/) should ship with Swift Testing from the first commit. Xcode 16 auto-detects the framework based on thePackages/CmuxSettings/Tests/CmuxSettingsTests/statement; no extraimport Testingconfiguration is required.Package.swift - Migration guide when touching an existing XCTest test. Convert in place: subclass becomes a
XCTestCase(or@Suite structif you need a reference type); eachfinal classbecomesfunc testFoo();@Test func foo()becomesXCTAssertEqual(a, b);#expect(a == b)becomesXCTAssertTrue(cond);#expect(cond)becomesXCTUnwrap(x);try #require(x)becomesXCTFail("msg").Issue.record("msg")becomessetUp()on the suite;init()becomestearDown(). Async setup isdeinit. Do not bulk-rewrite untouched tests; migrate incrementally as a side effect of editing the file.async init() - Parameterized tests use . Prefer this over duplicate test methods.
@Test(arguments: [...]) - Parallelization and shared state. Swift Testing runs tests in parallel by default, including across suites. If a suite genuinely needs ordering or guards shared mutable state, annotate it with instead of adding locks or sleeps.
.serialized - Tags with (or on a
@Test(.tags(.something))) let CI and local runs filter selectively.@Suite
Swift Testing是当前Apple支持的针对此代码库的测试基础组件(随Swift 6 / Xcode 16发布,支持我们目标的macOS版本)。所有非UI测试都应使用它。
- 所有单元测试和集成测试默认使用Swift Testing。 导入,用
Testing标注测试,用@Test进行分组,用@Suite和#expect(...)进行断言。除非是UI测试,否则不要用try #require(...)编写新测试。import XCTest - UI测试仍使用XCTest / XCUITest。 Swift Testing不支持UI测试(无集成)。
XCUIApplication下的文件继续使用cmuxUITests/+XCTestCase。不要迁移这些测试,也不要尝试将Swift Testing桥接到UI测试中。XCUIApplication - 新测试目标从Swift Testing开始。 每个新Swift包的目录(例如
Tests/<Name>Tests/)应从第一次提交起就使用Swift Testing。Xcode 16会根据Packages/CmuxSettings/Tests/CmuxSettingsTests/语句自动检测框架;无需额外的import Testing配置。Package.swift - 修改现有XCTest测试时的迁移指南。 就地转换:子类变为
XCTestCase(如果需要引用类型则为@Suite struct);每个final class变为func testFoo();@Test func foo()变为XCTAssertEqual(a, b);#expect(a == b)变为XCTAssertTrue(cond);#expect(cond)变为XCTUnwrap(x);try #require(x)变为XCTFail("msg")。Issue.record("msg")变为套件的setUp();init()变为tearDown()。异步初始化使用deinit。不要批量重写未改动的测试;在编辑文件时作为副作用逐步迁移。async init() - 参数化测试使用。优先使用此方式而非重复测试方法。
@Test(arguments: [...]) - 并行化与共享状态。 Swift Testing默认并行运行测试,包括跨套件运行。如果某个套件确实需要有序执行或保护共享可变状态,请用标注它,而非添加锁或睡眠。
.serialized - 标签使用(或在
@Test(.tags(.something))上),让CI和本地运行可以选择性过滤测试。@Suite
Test target validation
测试目标验证
reload.shcmuxreload.shcmuxTestscmuxUITestscmuxwrite(to:atomically:)TabManager.CommandResulttestscmux-unit-derivedDataPath /tmp/cmux-<tag>cmuxAppAppDelegatetestsreload.shreload.shcmuxreload.shcmuxTestscmuxUITestscmuxwrite(to:atomically:)TabManager.CommandResulttestscmux-unit-derivedDataPath /tmp/cmux-<tag>cmuxAppAppDelegatetestsreload.sh