添加 CloudKit 功能后 XCTest 失败

XCTest fails after adding CloudKit capability

启用 CloudKit 后,我的测试失败 运行,显然是因为测试包无法正确进行代码签名:

The bundle “XXXTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2020-01-06 09:11:40.551130+0100 XXX[2581:20975 (dlopen_preflight(/Users/xxx/Library/Developer/Xcode/DerivedData/XXX-gznytogyqukfvnawlueveokdvdrw/Build/Products/Debug/XXX.app/Contents/PlugIns/XXXTests.xctest/Contents/MacOS/XXXTests): no suitable image found.  Did find:
/Users/xxx/Library/Developer/Xcode/DerivedData/XXX-gznytogyqukfvnawlueveokdvdrw/Build/Products/Debug/XXX.app/Contents/PlugIns/XXXTests.xctest/Contents/MacOS/XXXTests: code signature invalid for '/Users/xxx/Library/Developer/Xcode/DerivedData/XXX-gznytogyqukfvnawlueveokdvdrw/Build/Products/Debug/XXX.app/Contents/PlugIns/XXXTests.xctest/Contents/MacOS/XXXTests')

我已经尝试清理构建文件夹、删除派生数据文件夹、手动下载配置文件、在网上搜索类似问题并尝试建议的解决方案,甚至重新启动我的 Mac 并重新集成 CocoaPods,尽管我认为这是完全不相关。

我错过了什么?

通过为测试目标提供它自己的没有任何 CloudKit 引用的权利文件解决了这个问题。同样对于测试目标,我使用 NSPersistentContainer 而不是 NSPersistentCloudKitContainer。换句话说:应用程序目标正在使用 CloudKit 但测试目标不是。这允许测试再次成功,同时应用程序本身可以通过 iCloud 进行同步。