iOS unit test: can't write file to iOS documents directory


I’m new to github actions. I’m trying to set it up to run the unit tests for my iOS-only Swift package. All of my tests involving writing txt files to the simulators documents directory are failing inside github actions, but working fine locally and working fine in a local test iOS project.

The error getting printed to the console is: “The file xxxxx doesn’t exist”. The file wouldn’t exist because the code is trying to create it. Does github actions have any kind of restrictions in accessing folders on simulators for writing data?

The file URL I was trying to write to with data.write(to: <url>) was:


Also is there anyway to access log files generated by xcode? When a test fails i’d love to just download the .xcresult file and open in locally. But I can’t see a way to do that. Is there anyway to access them, or actions to save them somewhere else?

Path would be something like:



Seems the issue was the documents directory is not created by default when using GHA, and the error from xcode is super misleading.

I changed my code to use:

try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

Instead and it works across the board. As for the logs, yes there are github actions available to upload logs as artifacts, this needs to be done for anything you want to save. There is a great github action that makes all of this much easier. Will auto upload logs during a failure and can be turned on to always upload if you want to see coverage for tests:

- uses: mxcl/xcodebuild@v1.5.1