xcode XCTest,无法加载测试包。测试启动时崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47313295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XCTest, Failed to load test bundle. Crash on test launch
提问by Andy Obusek
In Xcode 9.1, I added a Unit Test Target to an older project and I'm not able to get tests to run. The target crashes on launch with the following error in the console:
在 Xcode 9.1 中,我向旧项目添加了单元测试目标,但无法运行测试。目标在启动时崩溃,控制台中出现以下错误:
The bundle “XXXTests” couldn't be loaded because it doesn't contain a version for the current architecture*
无法加载包“XXXTests”,因为它不包含当前架构的版本*
Full output:
完整输出:
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}
(And then some diagnostic output that I didn't include)
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}
(然后是我没有包括的一些诊断输出)
Stuff I've checked after extensively googling:
我在广泛谷歌搜索后检查过的东西:
- Build Active Architecture Onlysetting is consistent across the app and test targets (With a value of Yes)
- Enable Testabilityis set to Yes for the main target
- I've deleted the target and started over, no luck
- Build Active Architecture Only设置在应用程序和测试目标之间保持一致(值为 Yes)
- 主要目标的“启用可测试性”设置为“是”
- 我已经删除了目标并重新开始,没有运气
How do I fix this?
我该如何解决?
回答by schmidt9
Make sure iOS Deployment target
fields of your application target and test target are the same
确保iOS Deployment target
您的应用程序目标和测试目标的字段相同
回答by Cirec Beback
I had the same issue. Simply building and running the associated application target on an iOS11.1 simulator (which happens to match the "iOS Deployment Target" of Test target) it started working.
我遇到过同样的问题。只需在 iOS11.1 模拟器(恰好与测试目标的“iOS 部署目标”匹配)上构建和运行关联的应用程序目标,它就可以开始工作了。
It seems starting the test the first time did not trigger a build of the test host. Subsequent runs seem to trigger the builds as needed and all is good.
第一次开始测试似乎没有触发测试主机的构建。随后的运行似乎会根据需要触发构建,一切都很好。
YMMV
青年会
回答by Hongli Yu
It happened to me when updating the Xcode version from 9.3 to 10. In my case, deleted the DerivedData, then the unit test works.
我在将 Xcode 版本从 9.3 更新到 10 时发生了这种情况。在我的情况下,删除了 DerivedData,然后单元测试工作。
回答by Nano Suárez
I had the same error. And for me what it worked was the following:
我有同样的错误。对我来说,它的作用如下:
- Select your test on the PROJECT NAVIGATOR
- on the right side, in FILE INSPECTOR choose the Target Membership, in this case your test target.
- 在项目导航器上选择您的测试
- 在右侧,在 FILE INSPECTOR 中选择Target Membership,在本例中为您的测试目标。
回答by Will Gwo
In my case, I had Macversion of OCMock.frameworked
in Link Binary with Libraries
build phrase for an iOSproject.
就我而言,我的Mac版本OCMock.frameworked
在Link Binary with Libraries
构建短语的iOS的项目。
Removing it solved the issue for me.
删除它为我解决了这个问题。
回答by zhuleixy
run with another ios11 device solve the problem
用另一个ios11设备运行解决问题