June 16, 2024

What is XCTest?

XCTest is the standard unit testing framework used for Apple's target platforms and in the XCode IDE.

Enabling XML Output

Test written in ObjectiveC and Swift projects using the XCTest framework can be run from the command line with xcodebuild. Unfortunately it only produces output in XCodes internal proprietary format. xcodebuild can produce JUnit compatible XML output using the xcbeautify open source tool.

Install it on macOS with Homebrew. Alternative installation instructions here.

1brew install xcbeautify

Then pipe the output of xcodebuild to xcbeautify with the --report junit option.

1xcodebuild test -scheme Testo2 | xcbeautify --report junit

This will produce a build/reports/junit.xml output file.

Test Suite naming

xcbeautify will use the name of file the tests are in as the name of the output <testsuite> and the function name as the name attribute of each <testcase> element.

Handling Retries

By default XCodebuild will not retry failed tests. You can enable retry with the -retry-tests-on-failure and set the number of retries with -test-iterations <num>. Ex:

1xcodebuild test -retry-tests-on-failure -test-iterations 3 -scheme Testo2

If you need to retry a lot of tests that is a strong indicator that you may have flaky tests. These are tests that sometimes pass and sometimes fail, slowing down your development process. You can get early access to Trunk’s new Flaky Tests tool to manage these types of tests better.

Try it yourself or
request a demo

Get started for free

Try it yourself or
Request a Demo

Free for first 5 users