Skip to content

Conversation

@AlexNachbaur
Copy link
Contributor

@AlexNachbaur AlexNachbaur commented Jul 29, 2025

Begin migrating the Swift SDK to use the new SwiftTesting framework, away from the legacy XCTest toolchain. This has a few advantages:

  • Improve stability, reliability, and performance of unit test runs
  • Helps to identify runtime errors and concurrency gaps, simplifying mocking and shared state isolation in tests, which can also help runtime stability
  • Better support tests in other non-Darwin runtime environments (e.g. Linux, Android, etc)

Copilot AI review requested due to automatic review settings July 29, 2025 19:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adopts SwiftTesting framework to replace XCTest throughout the test suite, aiming to improve test stability and runtime performance. The migration includes removing XCTestCase dependencies, converting test assertions to SwiftTesting syntax, and introducing trait-based test configuration for better test isolation and reusability.

  • Converts all test files from XCTest to SwiftTesting framework
  • Introduces trait-based test configuration system for better test isolation
  • Refactors test utilities to work with both XCTest and SwiftTesting
  • Improves concurrent testing capabilities with new helper functions

Reviewed Changes

Copilot reviewed 106 out of 106 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Tests/TestCommon/XCTestCase+Extensions.swift Converts XCTestCase extension methods to standalone public functions
Tests/TestCommon/URLSessionMock.swift Adds UUID to queue label and new requests filtering method
Tests/TestCommon/Traits/*.swift Introduces SwiftTesting traits for test configuration and dependency injection
Tests/TestCommon/SwiftTesting+Extensions.swift Adds new helper functions for async testing with confirmations
Tests/TestCommon/TimeInterval+Extensions.swift Adds new accuracy comparison methods for TimeInterval and Int
Tests/TestCommon/MockTimeCoordinator.swift New mock time coordinator for testing time-dependent functionality
Tests/*/*Tests.swift Converts all test files from XCTest to SwiftTesting syntax
Comments suppressed due to low confidence (2)

Tests/TestCommon/XCTestCase+Extensions.swift:178

  • [nitpick] The function name performConcurrent should be more descriptive. Consider renaming it to performConcurrentTests or runConcurrentOperations to better indicate its purpose.
public func performConcurrent(queueCount: Int = ProcessInfo.processInfo.activeProcessorCount,

Tests/AuthFoundationTests/TokenTests.swift:36

  • [nitpick] The parameter name test is ambiguous. Consider renaming it to body or operation to better indicate that it's the test closure to execute within the configured environment.
    func withTokenTestEnvironment<T>(_ test: (OpenIdConfiguration) throws -> T) throws -> T {

let userDefaults: UserDefaults
let storage: UserDefaultsTokenStorage

init() async throws {
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using async initializers can be problematic in test suites as they may not work correctly with all test frameworks. Consider using a setUp method or factory function instead.

Suggested change
init() async throws {
func setUp() async throws {

Copilot uses AI. Check for mistakes.
Comment on lines +37 to 38
init() {
token = try! Token(id: "TokenId",
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initializer contains a force unwrap (try!) which could cause tests to crash if token creation fails. Consider using proper error handling or making this a throwing initializer.

Suggested change
init() {
token = try! Token(id: "TokenId",
init() throws {
token = try Token(id: "TokenId",

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +51
let openIdConfiguration = try OpenIdConfiguration.jsonDecoder.decode(
OpenIdConfiguration.self,
from: try data(from: .module,
from: try data(from: Bundle.module,
for: "openid-configuration",
in: "MockResponses"))

Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The nested try statements make error handling unclear. Consider extracting the data loading to a separate variable for better readability and error handling.

Copilot uses AI. Check for mistakes.
This includes the use Swift6 toolchain for Swift 5 testing, and dropping support for Xcode 15.4.  This is acceptable because Xcode 15 is no longer supported by Apple, therefore it is no longer supported by us.
@AlexNachbaur AlexNachbaur force-pushed the SwiftTestingUpdates branch from 01df4d8 to 664f39f Compare July 29, 2025 21:00
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