Running CloudKit code in tests?

I like to write automated tests for my CloudKit code using the XCTest framework. Running a test case, gets a valid container object, gets a valid open database object, but then dies with the exception when I try to do something real:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to establish valid container/bundleID information' 

What I have tried so far:

  • Ive checked Info.plist for my test purpose, and the packet id matches the container id.
  • I tried [[NSBundle mainBundle] bundleIdentifier] to make sure it will return the correct package identifier.
  • I copied iCloud permissions from my main task.

But I still get the exception. Is there a way to get the CloudKit code running in the tests?

+6
source share
1 answer

The main thing is to run tests as "application tests." I am testing a user structure, so there is no application to run a test suite, no rights, and therefore CloudKit. I had to add the simple goal of β€œTest Rig” (Cocoa's empty application), set permissions there and set this test setup as a Bundle loader and a test node for a test suite. Then tests can use CloudKit just fine. Thanks for meeting me on the right track, @Ward!

+3
source

Source: https://habr.com/ru/post/970679/


All Articles