我安装了
Xcode 10并将我的iOS应用程序升级到
Swift 4.2.当我通过Xcode运行我的测试(UI和单元)时,在运行iOS 12的iPhone模拟器上,测试成功启动.当我尝试在运行先前iOS版本(例如iOS 10.3.1)的模拟器上运行测试时,我得到“无法加载测试包”.这些测试在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,但不是为iOS模拟器构建的,似乎它可能是关键.我该如何解决这个问题?
测试目标将iOS部署目标设置保留为默认值.
在Xcode 9.4中,这等于“iOS 11.4”,但由于某种原因,测试仍然可以在“iPhone 7(10.3)”模拟器上运行.在Xcode 10中,似乎行为发生了变化,因为测试不再运行在默认“iOS 12”之前运行iOS版本的模拟器上.