How can test targets be run with entitlement?

Does anyone know how I can include an entitlements file in my package so that the tests run with that entitlement?

Background

I've migrated some code into a little package that wraps the iOS Keychain which seems to be working well. However the tests are crashing with an error. The internet (and the Apple forums) suggest that the fix to this error is to have an entitlements file (even empty) when running the app.

I think I could also add an Xcode project and have that set up but it would be nicer to do it all within the Package approach.

This seems to be a fairly prominent KeyChain wrapping package but it doesn't seem to include a test target in its Package.swift: KeychainAccess/Package.swift at master · kishikawakatsumi/KeychainAccess · GitHub

Thanks,

Joseph

What's the error? If you're linking to anything iOS specific you can't build directly from SwiftPM since it doesn't know about the iOS toolchain. The easiest way around this is to build and test with xcodebuild

The error is this one is -34018 as discussed here: Confusion about access groups and … | Apple Developer Forums and particularly the answers on this page: https://developer.apple.com/forums/thread/51071?answerId=180654022#180654022 which seem to indicate that an entitlements file, even empty is required.

I'll try the xcodebuild approach when I get the chance and see if it works. Thanks for the suggestion.

While that will work to target an iOS device, for Keychain specifically you need a test host to get the proper entitlements which is not possible with the Swift Package Manager. You'll need to create an xcodeproj to handle that testing. I forgot that I actually asked about this very scenario way back Host Application for SPM Tests

2 Likes

When running a unit test target requiring a qualification keychain access it doesn't work out of the container on Xcode. You get some clear mistake in the comfort about a missing qualification. Everything turns out great on the test system however.

Thanks for the info and knowledge!

Terms of Service

Privacy Policy

Cookie Policy