I’d like to write automated tests for my CloudKit code using the XCTest framework. The test case runs, gets a valid container object, gets a valid public database object, but then dies with an exception when I try to do anything real:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Failed to establish valid container/bundleID information'
What I have tried so far:
Info.plist
for my test target and the bundle ID there corresponds to the container ID.[[NSBundle mainBundle] bundleIdentifier]
to make sure it returns the correct bundle ID.But I still get the exception. Is there a way to get the CloudKit code running in tests?
Yes you will require paid developer account for CloudKit.
Sign in to CloudKit Console at https://icloud.developer.apple.com/. Select the CloudKit Database from the app list. From the container selection drop-down at the top of the page, choose your app's container. Click the Record Types menu item in the Schema section to open the container's schema management page.
The main point is running the tests as “application tests”. I test a custom framework, so there’s no application to run the test suite in, no entitlements and therefore no CloudKit. I had to add a simple “Test Rig” target (an empty Cocoa app), set the entitlements there and set this test rig as a Bundle Loader and a Test Host for the test suite. Then the tests can use CloudKit just fine. Thank you for getting me on the right track, @Ward!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With