Xcode 在较旧的 iOS 模拟器上 运行 时 10 次测试失败 - "Failed to load test bundle... no suitable image found"

Xcode 10 test failure when running on older iOS simulators - "Failed to load test bundle... no suitable image found"

我已经安装了 Xcode 10 并将我的 iOS 应用程序升级到 Swift 4.2。当我通过 Xcode 运行 我的测试(UI 和 Unit)时,在 iPhone 模拟器 运行ning iOS 12 上,测试成功开始。当我尝试 运行 在模拟器 运行 上测试之前的 iOS 版本(例如 iOS 10.3.1)时,我得到一个 "failure to load the test bundle"。这些测试 运行ning 在 Xcode 9.4 上成功。我可以 运行 我的应用程序在这个较旧的模拟器上没有问题。

Xcode输出如下("Reading List"为应用名称):

2018-09-16 15:11:36.667 ReadingList[11401:11478426] Failed to load test bundle from file:///Users/andrewbennet/Library/Developer/Xcode/DerivedData/ReadingList-edsxqugqvkymbgfrbivbjmzebuya/Build/Products/Debug-iphonesimulator/ReadingList.app/PlugIns/ReadingList_UnitTests.xctest/: Error Domain=NSCocoaErrorDomain Code=3587 "dlopen_preflight(/Users/andrewbennet/Library/Developer/Xcode/DerivedData/ReadingList-edsxqugqvkymbgfrbivbjmzebuya/Build/Products/Debug-iphonesimulator/ReadingList.app/PlugIns/ReadingList_UnitTests.xctest/ReadingList_UnitTests): no suitable image found. Did find: /Users/andrewbennet/Library/Developer/Xcode/DerivedData/ReadingList-edsxqugqvkymbgfrbivbjmzebuya/Build/Products/Debug-iphonesimulator/ReadingList.app/PlugIns/ReadingList_UnitTests.xctest/ReadingList_UnitTests: mach-o, but not built for iOS simulator" UserInfo={NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Users/andrewbennet/Library/Developer/Xcode/DerivedData/ReadingList-edsxqugqvkymbgfrbivbjmzebuya/Build/Products/Debug-iphonesimulator/ReadingList.app/PlugIns/ReadingList_UnitTests.xctest/ReadingList_UnitTests, NSDebugDescription=dlopen_preflight(/Users/andrewbennet/Library/Developer/Xcode/DerivedData/ReadingList-edsxqugqvkymbgfrbivbjmzebuya/Build/Products/Debug-iphonesimulator/ReadingList.app/PlugIns/ReadingList_UnitTests.xctest/ReadingList_UnitTests): no suitable image found. Did find: /Users/andrewbennet/Library/Developer/Xcode/DerivedData/ReadingList-edsxqugqvkymbgfrbivbjmzebuya/Build/Products/Debug-iphonesimulator/ReadingList.app/PlugIns/ReadingList_UnitTests.xctest/ReadingList_UnitTests: mach-o, but not built for iOS simulator, NSBundlePath=/Users/andrewbennet/Library/Developer/Xcode/DerivedData/ReadingList-edsxqugqvkymbgfrbivbjmzebuya/Build/Products/Debug-iphonesimulator/ReadingList.app/PlugIns/ReadingList_UnitTests.xctest, NSLocalizedDescription=The bundle “ReadingList_UnitTests” couldn’t be loaded because it is damaged or missing necessary resources.}

mach-o, but not built for iOS simulator 行似乎是关键。我该如何解决这个问题?

测试目标将 iOS Deployment Target 设置保留为默认值。

在 Xcode 9.4 中,这等于 "iOS 11.4",但出于某种原因,测试仍然可以在 "iPhone 7 (10.3)" 模拟器上进行 运行。在 Xcode 10 中,行为似乎发生了变化,因为在默认 "iOS 12" 之前的模拟器 运行ning iOS 版本上不再进行测试 运行。

在项目导航器中,select 项目文件。 Select 项目配置中的目标 window。 Select 构建设置选项卡,(基本和级别) 向下滚动到 iOS 部署目标,然后 select 所需的 OS 版本。

这解决了我的问题。 干杯 rgds 戴夫