【问题标题】:XCTest, Failed to load test bundle. Crash on test launchXCTest,无法加载测试包。测试启动时崩溃
【发布时间】:2018-04-29 00:36:52
【问题描述】:

在 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} (然后是一些我没有包括在内的诊断输出)

我在广泛谷歌搜索后检查过的东西:

  • Build Active Architecture Only 设置在应用和测试目标中保持一致(值为 Yes)
  • 启用可测试性为主要目标设置为是
  • 我已经删除了目标并重新开始,没有运气

我该如何解决这个问题?

【问题讨论】:

  • 您的测试包的“有效架构”是什么?我想知道那与“仅构建活动架构”的交集是否为空。

标签: ios xcode xctest


【解决方案1】:

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

【讨论】:

  • 在我的情况下,测试目标具有“iOS 12”部署目标,但我在 iOS 11 模拟器上进行测试。
  • 对我来说同样的潜在问题有以下错误:xctest (32988) encountered an error (Failed to load the test bundle. (Underlying error: The package „TrackingTests“ could not be loaded because its damaged or has missing resources. dlopen_preflight( .../Debug-iphonesimulator/TrackingTests.xctest/TrackingTests): no suitable image found. Did find: ( .../Debug-iphonesimulator/TrackingTests.xctest/TrackingTests: mach-o, but not built for iOS simulator))
【解决方案2】:

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

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

YMMV

【讨论】:

    【解决方案3】:

    我在将 Xcode 版本从 9.3 更新到 10 时发生了这种情况。在我的情况下,删除了 DerivedData,然后单元测试工作。

    【讨论】:

      【解决方案4】:

      我有同样的错误。对我来说,它的作用如下:

      • 在 PROJECT NAVIGATOR 上选择您的测试
      • 在右侧,在 FILE INSPECTOR 中选择 Target Membership,在本例中是您的测试目标。

      【讨论】:

        【解决方案5】:

        就我而言,我在 iOS 项目的 Link Binary with Libraries 构建短语中使用了 Mac 版本的 OCMock.frameworked

        删除它为我解决了这个问题。

        【讨论】:

          【解决方案6】:

          用另一台ios11设备运行解决问题

          【讨论】:

            猜你喜欢
            • 2013-09-26
            • 2021-06-10
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-12-11
            相关资源
            最近更新 更多