Swift 5.10 Concurrency and XCTest

How baked are some of Xcode 15.3's concurrency warnings? One notable issue is that XCTestCase can no longer be annotated @MainActor:

@MainActor
class MyTests: XCTestCase {  ⚠️

:warning: Main actor-isolated class 'MyTests' has different actor isolation from nonisolated superclass 'XCTestCase'; this is an error in Swift 6

While it seems like the migration path is to move the actor annotation to the individual test case, that breaks quickly if you need to use a method like fulfillment(of:):

@MainActor
func testSomething() {
  let something = expectation(description: "something")
  await fulfillment(of: [something])  ⚠️
}

:warning: Passing argument of non-sendable type 'XCTestCase' outside of main actor-isolated context may introduce data races

And some XCTest APIs require @MainActor, like UI tests, which touch XCUIApplication, so these are just incompatible with fulfillment(of:) at the moment if you want to avoid introducing warnings, though we can workaround the problem with a synchronously call to the old API, which seems like a hack:

_ = { wait(for: [something]) }()

So I guess my question is, what is the correct migration path here? Just wait for the XCTest framework to address these issues?

16 Likes

We also experience these warnings and would like to know how to address them properly.

2 Likes