Xcode Cloud macOS won't run test scheme - "Failed to load the test bundle"

I'm new to Xcode cloud - working with a Mac OS app, build is working great. Now I am trying to add a Test action; the testing target builds but won't run, and the error indicates it can't find the testing bundle in the expected build output. There's also mention of a code signing error, but I have automatic code signing enabled with the same settings on test target as the app.

I am only running the unit test (XCTest) scheme, not the UI tests. When I run it locally from the IDE it works fine, either selecting the test scheme explicitly or as the test step of the app scheme.

I notice the XCTest target's scheme setup uses Debug builds and expects the test output to be in the Debug .app bundle, I thought perhaps that was the problem (in case only the release app bundle actually gets built in the Xcode Cloud environment). So I created a duplicate scheme and set the build targets to Release - again I can run this fine locally (after creating a release build), but it fails with the same error in Xcode cloud.

I also tried changing the code signing certificate from "Development" to "Sign to run locally" to see if that made a difference, but I get the same error. (It's using my developer account Team, and "Automatically manage signing".)

Can anyone relate the proper way to set up an XCTest scheme so that the tests will actually run in a Mac OS Xcode Cloud workflow? I'm using Xcode 14.0.1.

Here's the full error output, with [AppName] and [TestTargetName] substituted for the actual:

[AppName] (....) encountered an error (Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at /Volumes/workspace/resultbundle.xcresult. (Underlying Error: The bundle “[TestTargetName]” couldn’t be loaded. The bundle couldn’t be loaded. Try reinstalling the bundle. dlopen(/Volumes/workspace/TestProducts/Debug/[AppName].app/Contents/PlugIns/[TestTargetName].xctest/Contents/MacOS/[TestTargetName], 0x0109): tried: '/Volumes/workspace/TestProducts/Debug/[TestTargetName]' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/[TestTargetName]' (no such file), '/Volumes/workspace/TestProducts/Debug/[AppName].app/Contents/PlugIns/[TestTargetName].xctest/Contents/MacOS/[TestTargetName]' (code signature in <....> '/Volumes/workspace/TestProducts/Debug/[AppName].app/Contents/PlugIns/[TestTargetName].xctest/Contents/MacOS/[TestTargetName]' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?))))

Thanks!

Additional info: I discovered that this is not just an issue with Xcode cloud, I can reproduce by just trying to run the testing target from the command-line locally, with

xcodebuild -scheme (XCTest-scheme-name) test

I get the same error shown above, which does not occur when I run the Test action from the IDE. In this case it's looking for the test file in the Debug .app build in derived data - and the file is actually there. Any suggestions? Is this a code-signing issue?

Update, back to square 1... After switching code signing setting to Run Locally and back to Developer, and cleaning, the xcodebuild test command succeeds from the Terminal with this target. Still fails on Xcode Cloud however, including after a clean environment.

This is a known issue. Even though we already know about it, we'd still really appreciate anyone encountering this to file a bug report thorough Feedback Assistant to aid our investigation. When you open that report, please post the FB number here.

As a workaround, you can disable the Hardened Runtime from the Capabilities tab in Xcode. However, this reduces the security of the app, and so this workaround may not make sense for all apps.

Thanks, my feedback report # is FB11845080.

I'm running into the same issue. I believe it has something to do with embedded dependencies (e.g. system extensions, drivers, privileged helpers). My solution has been to generate a separate "test" build target that does not embed these dependencies in the app bundle. It's quite frustrating, so I hope the issue on Xcode Cloud is resolved soon.

I've seen this problem for the longest time, just submitted my feedback -

FB11983783

I'm seeing something very similar, I've raised FB11986152 and attached the Xcode Cloud log output. For now I'm going to test locally before pushing.

Any update? I am desperate to find a solution!

I'm also encountering this.

Feedback: FB13554487, including logs and project source, and a link to the failing build.

Thanks.

I've filed FB13786010. It's frustrating that this is still happening over a year later.

Xcode Cloud macOS won't run test scheme - "Failed to load the test bundle"
 
 
Q