Actually I got a working soloution that does not require any hacks
The first invocation of xcodebuild
will create a xctestrun
file:
xcrun xcodebuild build-for-testing -workspace <project_root>/<project_name>.xcworkspace -scheme <scheme> -destination 'platform=iOS Simulator,id=2253C0D7-C198-44AD-A98B-11301FD88F30'
This file will be located in the DerivedData folder and be named like this:
~/Library/Developer/Xcode/DerivedData/<build_folder>/Build/Products/<scheme>_<test_plan_name>_<device_type><ios-version>-<architecture>.xctestrun
An example would be MyScheme_Screenshots_iphonesimulator16.4-arm64.xctestrun
The second invocation of xcodebuild
then uses this file to run the tests. It is not allowed to specify any of [-project, -scheme, -workspace]
when using -xctestrun
:
xcrun xcodebuild test-without-building -destination 'platform=iOS Simulator,id=2253C0D7-C198-44AD-A98B-11301FD88F30' -xctestrun ~/Library/Developer/Xcode/DerivedData/<build_folder>/Build/Products/<scheme>_<test_plan_name>_<device_type><ios-version>-<architecture>.xctestrun
Hope this helps you folks
PS: Here you can find the Pull Request for my command line tool Snap
that integrates this fix. Snap creates screenshots using Xcode TestPlans. Super useful for CI