How to setup keychain library tests in Xcode 8 / iOS 10

Update: The Keychin bug was fixed in Xcode 8.2. Now the unit tests work if Host Application is selected in your test target (see Step 3 below).

A Keychain is a secure storage in Apple devices used for keeping small bits of information like passwords. The testing of Keychain code has never been harder than in Xcode 8 and iOS 10. This tutorial shows thirteen easy steps (sorry for the sarcasm) that I needed to go through to make the unit tests work in the Keychain Swift library.

1. Turn on signing in the app target

  1. Open the General tab in your app target.
  2. Turn on Automatically Manage Signing and select your team in the Signing section.

Enable keychain sharing in app target in Xcode

2. Turn on the Keychain Sharing

  1. Open the Capabilities tab in your app target.
  2. Turn on the Keychain Sharing.

Turn on keychain sharing in app target in Xcode

3. Finally, configure the test target

  1. Open the General tab in your test target.
  2. Select your app in the Host Application.
  3. Turn on Automatically Manage Signing and select your team.

Enable keychain testing in Xcode

Is there an easier way?

Please feel free to share in the comments if you know an easier way to make keychain unit test work in Xcode 8. It would be also interesting to know why Apple introduced this change or if it is merely a bug.

References

  • A thread on Apple Developer Forums.

  • An answer on Stack Overflow.







Wooooow!