Since Xcode 11 the resulting output file from automated testing (Unit tests or UITests) has become .xcresult (See screenshot below).
Before Xcode 11, a TestSummaries.plist file was created in the test folder that was used to build a JUnit file.
The JUnit file was then used in Jenkins CI to:
- Show test results
- Send e-mails notifying members of the team about failures.
- Keep an archive of results and their parameters
But now it seems that there is no available command line tool to parse the .xcresult file that contains:
- Test results
- Code coverage
- Screenshots (not so interested in these)
I've tried xcpretty: https://github.com/xcpretty/xcpretty but that one just says that 0 tests have been executed, when like 68 are actually executed
Not sure if this matters but I use .xctestplan and below xcodebuild command
xcodebuild -scheme Debug -workspace MyApp.xcworkspace -destination 'platform=iOS Simulator,OS=12.4,name=iPhone Xs Max' test -testPlan UnitTests
I also saw that there was a command line tool that came installed with Xcode 11 which solves part of the puzzle:
$ xcrun xcresulttool --path ResultBundle.xcresult --format json > ResultBundle.json
But that only parses one layer
I've also looked at xcparse, and they seem to be on the right track, like, it solved parsing the .xcresult file and getting code coverage and screenshots, but they somehow didn't include the most vital part of the .xcresult (for our company that is) which is the results of the tests. Like 47 succeeded 4 failed and these failed, that part.
In summary: How can I convert the .xcresult to a JUnit file?
Bonus: I saw that Apple included a detailed description of the format of .xcresult by calling:
xcrun xcresulttool formatDescription
Apple made this so that future changes to the .xcresult format can be automatically processed by third party libraries, so a solution that would produce a JUnit file is fine, a solution that produces a JUnit file and somehow works with "xcrun xcresulttool formatDescription" is even better as it is future proof :)
I use the xcpretty tool for converting the results into JUnit format and that works for me. But I don't use a testPlan.
Maybe my command, that I use in my jenkins CI helps you further
xcodebuild -derivedDataPath DerivedData -scheme "<MyShema>" -destination 'platform=iOS Simulator,name=iPad Pro (9.7-inch),OS=13.5' test | /usr/local/bin/xcpretty --report junit
After that the report is saved in build/reports/junit.xml
.
EDIT:
I found on this site https://www.raywenderlich.com/2841-beginning-automated-testing-with-xcode-part-2-2 an interesting tool for converting to junit test results. (https://github.com/ciryon/OCUnit2JUnit)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With