Where does my Swift app's print output go during XCTest?

I only see the output from the XCTest itself.

Xcode: Version 15.2 (15C500b)

Answered by Developer Tools Engineer in 789225022

The generally recommended way to get logs (and other attachments) to appear in your result is to use XCTContext.runActivity: https://developer.apple.com/documentation/xctest/xctcontext/2923506-runactivity

This will let you print the activity in your result, and will wrap child activities/other actions within it in the result

You can also add attachments (like snippets of text) to the activity using the XCTAttachment API's https://developer.apple.com/documentation/xctest/activities_and_attachments/adding_attachments_to_tests_activities_and_issues

Hope this is helpful!

I’m not sure if this is the only place where it ends up, but I was able to find this as follows:

  1. Switch to the Reports navigator.

  2. On the left, select the Log item.

  3. In the editor, select the “Run test suite NNN”, where NNN is the name of the test suite containing my test.

  4. Choose Editor > Expand Selected Transcripts.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Changed it to a comment. Please see above.

I'm looking for the traces coming from my app's print statements.

Right. And that’s exactly what this shows.

I tested this with Xcode 15.2 with a new project created from the macOS > App template. I added a print call to the example test case:

I then ran the test and looked at the log:

As you can see, the Hello Cruel World I printed shows up in the log.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The generally recommended way to get logs (and other attachments) to appear in your result is to use XCTContext.runActivity: https://developer.apple.com/documentation/xctest/xctcontext/2923506-runactivity

This will let you print the activity in your result, and will wrap child activities/other actions within it in the result

You can also add attachments (like snippets of text) to the activity using the XCTAttachment API's https://developer.apple.com/documentation/xctest/activities_and_attachments/adding_attachments_to_tests_activities_and_issues

Hope this is helpful!

Where does my Swift app's print output go during XCTest?
 
 
Q