I also need to execute unit tests inside a framework and I still encounter the problem with xcode 8.1.
Right. This is a well-known issue with library tests (sometimes called logic tests by Xcode). Those tests are run by a tool (
xctest
) that does not have entitlements. Historically this caused problems for folks using custom entitlements (to access CloudKit, for example) but now it affects folks using the keychain as well.
AFAIK there’s no direct workaround. However, I believe you can avoid the problem by running this test code within your app (in the docs this is called an app test). Because these run inside your app, they get the app’s entitlements.
If you don’t have an app handy, you can create a dummy one just to host the tests.
Please try this out and let us know if you hit any snags.
Oh, and don’t let the availability of a workaround prevent you from filing a bug about this. Xcode should be able to run library tests with entitlements, and this recent keychain change makes this even more important.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"