Swift Tests

I have a question about swift testing. I found it necessary to rewrite several tests for a library, so I decided to try my hand at swift testing. I put them all in a suite and took what had been in setUpWithError() and put it in init() for the suite. Each test runs fine when executed separately, but the suite fails when I try to run it. A similar procedure with XCTest works fine. It seems to have to do with concurrency. If I make the suite a main actor, it works fine. Could someone explain this situation, and are there other alternatives to declaring a main actor for the suite.

It seems that just replacing XCTest wit Swift Test is not quite. enough.

Rick

Swift Testing runs tests parallel in the same process. XCTest runs tests parallel in their own processes. In the migration docs, the suggestion is to use the .serialized trait to match the behavior of XCTest: https://swiftpackageindex.com/swiftlang/swift-testing/main/documentation/testing/migratingfromxctest#Run-tests-sequentially

If you want to take advantage of parallelization, you'll need to isolate what is bleeding between tests and control it.

1 Like

Thanks, I missed that.