I have an existing XCTest that:
- Reads in a text file with 512 lines of short strings
- Splits the string and iterates over each line in a for loop
- Tests that the string is processed as expected
The test takes about 0.231 seconds to run.
I moved this to be a parameterized test in Swift Testing with the following changes:
- Reading the text file and splitting the string happen in a static fixture method
- The resulting arguments are passed to the parameterized test
The migrated test took an average of 3.383 seconds over five runs, a good deal slower.
And after running the test Xcode remains unresponsive for an average of 16.218 seconds waiting to 'acknowledge that testing finished'.
This is a Swift package building and testing in Xcode 16 beta.
I have made sure the autogenerated test plan has the "Execute in parallel (if possible)" checkbox checked. (Otherwise the test takes about 23 seconds).
This is on a M3 Max MacBook Pro, Xcode 16 beta, macOS 14.5.
Is this amount of performance hit expected moving an existing test to parameterized tests? (Both the longer test itself and the Xcode delay at the end)
Is there anything I can do to make it faster (possibly turn off logging of each parameter test to the console unless it is a failure?)
Note that migrating the test from XCTest to Swift Testing directly, without a parameterized test, the time is in the same .21 second range and there is no Xcode pause at the end of the test.
So, I do have an easy workaround, but unfortunately it is "keep using loops inside the test". (EDIT: a second, better workaround is to run the package tests using swift test
instead of in Xcode.)
EDIT: Moving the post to the correct category.
EDIT 2: TL;DR It appears that how the tests are run for a package in Xcode may be causing the slowness.
Running the same test using swift test --enable-swift-testing
in the first Xcode beta results in an average test time of 0.065 seconds. Definitely faster than the XCTest loop version of the test!