Tests involving keychain access in iOS

I have tests that interact with the keychain in iOS, which fails on Bitrise and succeeds locally.

I’m using the simulator when testing locally.

It’s only these tests that fail, that was recently added (note, it’s the unit-tests for library so I’ve added a simple hosting application for it to run locally, that thats a part of the projects, so…)

Any ideas?

fails on Bitrise and succeeds locally.

Can you please follow this guide and let us know if that helps:

Also, how do you run your tests? With our Xcode Test step?
What’s the error?

:heavy_check_mark:️ Can build from clean clone

:heavy_check_mark:️ Can build locally with bitrise cli

:heavy_check_mark:️ Testing using Xcode: Unit Test step: 1.19.0

The error that Im seeing is simply that my unit-tests fails (the ones interacting with the keychaing)

Anything else in the logs, why it fails?

Please make sure that you have the Deploy to Bitrise.io step after the Xcode Test step in the workflow, that should attach the full/raw, unfiltered Xcode log to the build (top of the build page, Apps & Artifacts).

Another thing: did you try to Reset the iOS Simulator on your Mac and then running the tests again? It’s quite a common source of these “works locally but not on bitrise.io” issues that the app behaves a bit differently at the first run, e.g. it presents a popup which only have to be accepted once (at the first run, then it’s stored in user defaults).

  • I don’t deploy to bitrise.io since it’s a library
  • The tests success locally even after resetting the simulator

More exact error:

/Users/vagrant/git/../..Tests.swift:11: error: -[..Tests.KeychainTests testErase] : XCTAssertTrue failed - 
Nothing was retrieved from the keychain. Status: The operation couldn’t be completed. (swift.keychain.error error -25300.): -25300
1 Like

The Deploy to Bitrise.io step can be used for attaching any artifact to the build, most of our steps share additional / debug logs which can help with debugging issues, and are stored in the $BITRISE_DEPLOY_DIR which is the default dir deployed by Deploy to Bitrise.io.

Hmm… That’s strange. Did you run the tests in the same iOS Simulator / iOS version?

It seems the error code 25300 is simply that the item does not exist in the keychain. A possible debug idea:

https://forums.developer.apple.com/thread/11129

-25300 is errSecItemNotFound, which is a pretty standard keychain error. To debug this, my recommendation is that, when it occurs, you dump out the contents of your keychain to verify that things are in the state that you expect them to be in.

You can find more details/tips at the link.