XCTest 在添加 CloudKit 功能后失败。

huangapple go评论71阅读模式
英文:

XCTest fails after adding CloudKit capability

问题

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

损坏或缺少必要资源,无法加载捆绑包“XXXTests”。尝试重新安装捆绑包。
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): 未找到合适的映像。已找到:
/Users/xxx/Library/Developer/Xcode/DerivedData/XXX-gznytogyqukfvnawlueveokdvdrw/Build/Products/Debug/XXX.app/Contents/PlugIns/XXXTests.xctest/Contents/MacOS/XXXTests: 对于'/Users/xxx/Library/Developer/Xcode/DerivedData/XXX-gznytogyqukfvnawlueveokdvdrw/Build/Products/Debug/XXX.app/Contents/PlugIns/XXXTests.xctest/Contents/MacOS/XXXTests'的代码签名无效)

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

我漏掉了什么?

英文:

After I enabled CloudKit my tests fail to run, apparently because the test bundle cannot be code signed correctly:

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')

I already tried cleaning the build folder, remove the derived data folder, manually download profiles, searched the web for similar issues and tried proposed solutions, even restarted my Mac and reintegrated CocoaPods although I think this is completely unrelated.

What am I missing?

答案1

得分: 1

解决方法是为测试目标提供一个自己的entitlements文件,该文件不包含任何CloudKit引用。此外,对于测试目标,我使用了NSPersistentContainer而不是NSPersistentCloudKitContainer。换句话说:应用目标正在使用CloudKit,但测试目标不是。这使得测试可以再次成功,同时应用本身可以通过iCloud进行同步。

英文:

Solved it by giving the test target its own entitlements file that does not have any CloudKit references. Also for the test target I used NSPersistentContainer instead of NSPersistentCloudKitContainer. In other words: the application target is using CloudKit but the test target is not. This allowed the tests to succeed again while the application itself is enabled to synchronise via iCloud.

huangapple
  • 本文由 发表于 2020年1月6日 16:23:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608797.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定