Improving swift-testing performance for @MainActor @Observable view models

I’m using swift-testing and all my view models are marked @MainActor and @Observable. My tests for these view models run slowly, and I suspect it’s because they all execute on the main actor, preventing parallelization.

As a rough comparison, I leveraged AI and rewrote the same tests using XCTest and saw ~50% faster execution. My working theory is that XCTest is benefiting from higher-level parallelism (e.g., process level parallelization), while swift-testing currently isn’t, at least in my setup.
so I guess I have a few questions:

  1. Am I doing something suboptimal in terms of how to use swift-testing to test view models?
  2. Are there any knobs I can turn to increase the level of parallelism with swift-testing?

Swift Testing implements parallelization in-process. Multiprocess parallelization is a future direction we are interested in exploring in the future on platforms where it's possible to implement.

2 Likes

Which tool or IDE you use to run your tests can also be a factor. Are you using Swift Package Manager, Xcode, xcodebuild, VS Code, or some other tool?

I’m using Xcode locally and xcodebuild in a CI environment.

I had mentioned this to @grynspan on Slack, but I tried the -parallelize-tests-among-destinations flag with the hope that I could at least distribute the test among separate simulators. However, that doesn’t seem to be supported either.

Please forgive me, but I don't recall discussing this topic with you outside this thread.

No worries - i asked about this in the #testing channel on iOS Folks early December last year. You suggested that I post here, but I just haven’t gotten around to it until now.