Hello,
I'm currently working on a project that compares test performance between the XCTest and Testing. However, I've found myself a bit stuck in the process - specifically, on how to ensure the results are as accurate as possible.
To provide a bit more context, here are a few approaches I initially wanted to take, although they didn’t work out as expected. First, each project was intended to include a Package.swift file with a structure resembling the following:
let package = Package(
...,
targets: [
...,
.testTarget(
name: "FooTests",
dependencies: [...]
),
.testTarget(
name: "FooXCTests",
dependencies: [...]
),
...
]
)
Where FooTests and FooXCTests would use, respectively Testing and XCTest without mixing these two in the same target, and would "share" set of tests written using their native API's (if possible).
I considered below approach of getting time measurements using swift test command, which works great for Testing, but not so great for XCTest.
swift test \
--filter FooXCTests|...|..XCTests \
--enable-xctest \
--disable-swift-testing \
--xunit-output ./output.xml
After running above command, no output file would be generated (I have explicitly passed --disable-swift-testing to not to generate empty output for swift testing). However, after looking at SwiftTestCommand.swift I have found that this works when --parallel flag is passed. However, at this point (maybe wrongly) I started thinking that using xcodebuild would be better approach here, as it would always allow me to test projects in comparison to using swift test which would require them to support macOS as well as parallel testing.
My next idea was to abandon swift test, and use xcodebuild - not much of a refactor, I could simply create two test plans - each containing only the test targets written with either Testing or XCTest.
xcodebuild \
-scheme swift-foo \
-destination "platform=macOS,arch=arm64,name=My Mac" \
-testPlan foo-swift-testing \
-resultBundlePath ./output.xcresult \
-derivedDataPath ./DerrivedData/ \
clean \
test
Another command - same story :), this works like a charm, except when the test plan contains tests written only using Testing. In that case, it seems that the output.xcresult file does not capture valid test durations - they are either missing or always reported as one second.
Taking my approaches and their results into account - where neither command produces reliable results - would it be valid to capture the test run name and duration directly from the stdout output (e.g. from xcodebuild) instead of, for example, using the .xcresult file? Or are there perhaps better methods to extract this information?
Thank you for taking the time to read this. I would greatly appreciate any insights on how to approach this situation.