Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCTest, Failed to load test bundle. Crash on test launch

Tags:

xcode

ios

xctest

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:

The bundle “XXXTests” couldn’t be loaded because it doesn’t contain a version for the current architecture*

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)

Stuff I've checked after extensively googling:

  • Build Active Architecture Only setting is consistent across the app and test targets (With a value of Yes)
  • Enable Testability is set to Yes for the main target
  • I've deleted the target and started over, no luck

How do I fix this?

like image 501
Andy Obusek Avatar asked Nov 15 '17 17:11

Andy Obusek


3 Answers

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.
like image 144
Nano Suárez Avatar answered Sep 26 '22 03:09

Nano Suárez


Make sure iOS Deployment target fields of your application target and test target are the same

like image 24
schmidt9 Avatar answered Nov 10 '22 04:11

schmidt9


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.

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

like image 7
Cirec Beback Avatar answered Nov 10 '22 05:11

Cirec Beback