Can't run unit tests with Xcode 12.5. Code signing?

After updating to 12.5, I now get an error trying to run my unit tests. This is for a macOS app.

dyld: warning: could not load inserted library '/[...]/DerivedData/[...]/Contents/Frameworks/libXCTestBundleInject.dylib' into hardened process because no suitable image found.  Did find:
/[...]/libXCTestBundleInject.dylib: code signature in (/[...]/libXCTestBundleInject.dylib) not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)

Anyone else face and fix this, or understand what it is?

I changed the "Signing Certificate" in my test target to "Sign to Run Locally" (from "Development") to see if that would help. It didn't fix it.

Replies

Apparently, I can't edit questions here like you can on StackOverflow. This is not caused by Xcode 12.5 exactly, it happened because I followed the suggestion to enable the "Hardened Runtime".

So my question is really: can you unit test when the "Enable Hardened Runtime" build setting is "YES"?
  • This is a known issue in Xcode Cloud. The current workaround is to set the "Enabled Hardened Runtime" build setting to "NO" for test targets.

Add a Comment

I can't edit questions here like you can on StackOverflow.

Indeed, DevForums is not Stack Overflow. You can edit a post for a while after posting it but then it gets set in stone. For this and other tidbits, see Developer > Support > Developer Forums.

can you unit test when the "Enable Hardened Runtime" build setting is
"YES"?

The hardened runtime enables library validation, which enforces that all code loaded by a process be either signed by you or signed by Apple. It sounds like your app is signed by your but your unit test bundle is not.

Share and Enjoy

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

I faced the same issue when adding a unit testing bundle target to my project after already signing and distributing it to the Mac App Store. I was using the "Automatically manage signing" checkbox for my main app target.

To fix this I had to uncheck that box and check it again before adding the unit testing bundle. I don't know what happened under the hood, but this solved it for me.