XCTest,无法加载测试包.测试发布时崩溃

And*_*sek 5 xcode ios xctest

在Xcode 9.1中,我为一个较旧的项目添加了一个单元测试目标,但我无法运行测试.目标在启动时崩溃,并在控制台中出现以下错误:

无法加载捆绑包"XXXTests",因为它不包含当前体系结构的版本*

全输出:

2017-11-15 11:52:40.973 XXX[54962:16511010] Failed to load test bundle from file:///Users/XXX/Library/Developer/Xcode/DerivedData/XXX-gaxtmzjadfkxzsdciqnpmyczgntj/Build/Products/DEV-iphonesimulator/XXX.app/PlugIns/XXXTests.xctest/: Error Domain=NSCocoaErrorDomain Code=3585 "dlopen_preflight(/Users/XXX/Library/Developer/Xcode/DerivedData/XXX-gaxtmzjadfkxzsdciqnpmyczgntj/Build/Products/DEV-iphonesimulator/XXX.app/PlugIns/XXXTests.xctest/XXXTests): no suitable image found. Did find: /Users/XXX/Library/Developer/Xcode/DerivedData/XXX-gaxtmzjadfkxzsdciqnpmyczgntj/Build/Products/DEV-iphonesimulator/XXX.app/PlugIns/XXXTests.xctest/XXXTests: mach-o, but wrong architecture" UserInfo={NSLocalizedRecoverySuggestion=Try installing a universal version of the bundle., NSFilePath=/Users/XXX/Library/Developer/Xcode/DerivedData/XXX-gaxtmzjadfkxzsdciqnpmyczgntj/Build/Products/DEV-iphonesimulator/XXX.app/PlugIns/XXXTests.xctest/XXXTests, NSLocalizedFailureReason=The bundle doesn’t contain a version for the current architecture., NSLocalizedDescription=The bundle “XXXTests” couldn’t be loaded because it doesn’t contain a version for the current architecture., NSDebugDescription=dlopen_preflight(/Users/XXX/Library/Developer/Xcode/DerivedData/XXX-gaxtmzjadfkxzsdciqnpmyczgntj/Build/Products/DEV-iphonesimulator/XXX.app/PlugIns/XXXTests.xctest/XXXTests): no suitable image found. Did find: /Users/XXX/Library/Developer/Xcode/DerivedData/XXX-gaxtmzjadfkxzsdciqnpmyczgntj/Build/Products/DEV-iphonesimulator/XXX.app/PlugIns/XXXTests.xctest/XXXTests: mach-o, but wrong architecture, NSBundlePath=/Users/XXX/Library/Developer/Xcode/DerivedData/XXX-gaxtmzjadfkxzsdciqnpmyczgntj/Build/Products/DEV-iphonesimulator/XXX.app/PlugIns/XXXTests.xctest} (然后我没有包含一些诊断输出)

我经过广泛的谷歌搜索后检查了一下:

  • "仅构建活动体系结构"设置在应用程序和测试目标中保持一致(值为"是")
  • 主要目标的" 启用可测试性"设置为"是"
  • 我删除了目标并重新开始,没有运气

我该如何解决?

sch*_*dt9 19

确保iOS Deployment target应用程序目标和测试目标的字段相同


Cir*_*ack 6

我遇到过同样的问题。只需在 iOS11.1 模拟器(恰好与测试目标的“iOS 部署目标”匹配)上构建和运行关联的应用程序目标,它就可以开始工作了。

第一次开始测试似乎没有触发测试主机的构建。后续运行似乎会根据需要触发构建,一切都很好。

青年会