Skip to content

test: Migrate the test suite from XCTest to swift-testing#105

Merged
keelerm84 merged 1 commit into
4.xfrom
mk/SDK-2606/swift-testing-migration
Jun 26, 2026
Merged

test: Migrate the test suite from XCTest to swift-testing#105
keelerm84 merged 1 commit into
4.xfrom
mk/SDK-2606/swift-testing-migration

Conversation

@keelerm84

@keelerm84 keelerm84 commented Jun 26, 2026

Copy link
Copy Markdown
Member

Ports the test suite to swift-testing (@Suite/@Test/#expect) to align with
swift-core, which uses swift-testing throughout. No behavior or coverage change:
same assertions and the same network-mock scenarios.

  • Convert UTF8LineParserTests, EventParserTests, and LDSwiftEventSourceTests from
    XCTestCase subclasses to @suite types. setUp/tearDown become init/deinit on
    final-class suites so the "reset works" / "no leftover events or requests"
    invariants are still enforced after each test (verified that an issue recorded
    in deinit is attributed to the owning test).
  • Mark LDSwiftEventSourceTests .serialized: it shares process-global state
    (URLProtocol registration and the static MockingProtocol.requested sink), which
    XCTest ran serially and swift-testing would otherwise parallelize. The parser
    suites use per-test fixtures and stay parallel-safe.
  • The connectionErrorHandler runs on the URLSession delegate queue, off the test's
    task, where swift-testing's task-local current-test is not set. Capture what it
    observes into a lock-protected Box and assert on the test thread instead of
    calling #expect from the callback.
  • EventSink swaps XCTFail for Issue.record; it keeps its NSCondition blocking
    wait, which remains the right fit for the URLProtocol delegate-thread handoff.
  • Drop the xcpretty pipe from the macOS SwiftPM test action: xcpretty parses
    XCTest output, not swift-testing, and piping through it without pipefail would
    garble output and mask failures. Plain swift test gates correctly and prints
    swift-testing's native output.

Note

Low Risk
Changes are limited to tests and CI wiring; production EventSource behavior is not modified.

Overview
Moves the SwiftPM test suite from XCTest to swift-testing (@Suite / @Test / #expect) with the same scenarios and assertions; library code is unchanged.

Suites replace setUp/tearDown with init/deinit on final classes so cleanup checks (e.g. no leftover mock events) still run per test. LDSwiftEventSourceTests is marked .serialized because it shares process-global URLProtocol registration and a static mock request sink that XCTest ran serially but swift-testing would parallelize.

Tests that assert inside connectionErrorHandler (URLSession delegate queue) now capture observations in a Box and #expect on the test thread instead of asserting from the callback. EventSink reports failures via Issue.record instead of XCTFail.

The SwiftPM GitHub action runs plain swift test instead of piping through xcpretty, which only understood XCTest output and could hide failures.

Reviewed by Cursor Bugbot for commit 69aff96. Bugbot is set up for automated code reviews on this repo. Configure here.

@keelerm84 keelerm84 requested a review from a team as a code owner June 26, 2026 15:06
Base automatically changed from mk/SDK-2605/v6-test-target to 4.x June 26, 2026 18:44
Ports the test suite to swift-testing (@Suite/@Test/#expect) to align with
swift-core, which uses swift-testing throughout. No behavior or coverage change:
same assertions and the same network-mock scenarios.

- Convert UTF8LineParserTests, EventParserTests, and LDSwiftEventSourceTests from
  XCTestCase subclasses to @suite types. setUp/tearDown become init/deinit on
  final-class suites so the "reset works" / "no leftover events or requests"
  invariants are still enforced after each test (verified that an issue recorded
  in deinit is attributed to the owning test).
- Mark LDSwiftEventSourceTests .serialized: it shares process-global state
  (URLProtocol registration and the static MockingProtocol.requested sink), which
  XCTest ran serially and swift-testing would otherwise parallelize. The parser
  suites use per-test fixtures and stay parallel-safe.
- The connectionErrorHandler runs on the URLSession delegate queue, off the test's
  task, where swift-testing's task-local current-test is not set. Capture what it
  observes into a lock-protected Box and assert on the test thread instead of
  calling #expect from the callback.
- EventSink swaps XCTFail for Issue.record; it keeps its NSCondition blocking
  wait, which remains the right fit for the URLProtocol delegate-thread handoff.
- Drop the xcpretty pipe from the macOS SwiftPM test action: xcpretty parses
  XCTest output, not swift-testing, and piping through it without pipefail would
  garble output and mask failures. Plain `swift test` gates correctly and prints
  swift-testing's native output.
@keelerm84 keelerm84 force-pushed the mk/SDK-2606/swift-testing-migration branch from 2d29249 to 69aff96 Compare June 26, 2026 18:48
@keelerm84 keelerm84 merged commit 4b01403 into 4.x Jun 26, 2026
15 checks passed
@keelerm84 keelerm84 deleted the mk/SDK-2606/swift-testing-migration branch June 26, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants