30

I've tried adding a test target on Xcode 5 using the Add Target -> Add Cocoa Touch Unit Testing Bundle. However, when I run the test, I get the following error:

2013-09-24 10:43:14.446 Stack Exchange[48895:c07] Error loading /Users/arielitovsky/Library/Developer/Xcode/DerivedData/MyApp-fjegcztcnwxqdfdimhonqzzqpdwr/Build/Products/Debug-iphonesimulator/Stack Exchange Tests.xctest/Stack Exchange Tests: dlopen(/Users/arielitovsky/Library/Developer/Xcode/DerivedData/MyApp-fjegcztcnwxqdfdimhonqzzqpdwr/Build/Products/Debug-iphonesimulator/Stack Exchange Tests.xctest/Stack Exchange Tests, 262): Library not loaded: /Developer/Library/Frameworks/XCTest.framework/XCTest Referenced from: /Users/arielitovsky/Library/Developer/Xcode/DerivedData/MyApp-fjegcztcnwxqdfdimhonqzzqpdwr/Build/Products/Debug-iphonesimulator/Stack Exchange Tests.xctest/Stack Exchange Tests Reason: image not found IDEBundleInjection.c: Error loading bundle '/Users/arielitovsky/Library/Developer/Xcode/DerivedData/MyApp-fjegcztcnwxqdfdimhonqzzqpdwr/Build/Products/Debug-iphonesimulator/Stack Exchange Tests.xctest' Program ended with exit code: 0

Why isn't this working?

bneely
  • 9,083
  • 4
  • 38
  • 46
Arie Litovsky
  • 4,893
  • 2
  • 35
  • 40

3 Answers3

76

You must run your test on the iOS 7 simulator. It will not work on iOS 6.x.

Arie Litovsky
  • 4,893
  • 2
  • 35
  • 40
  • You just made my day. – shawnwall Sep 26 '13 at 14:30
  • glad I could help :) I figure it would eventually happen to somebody – Arie Litovsky Sep 26 '13 at 14:40
  • Great it all compiles and runs now, except my XCTest tests don't seem to run. The green triangles next to OCUnit tests are hollow next to me XCTest tests. – Erik Engheim Sep 27 '13 at 15:24
  • Did you make sure to set them up in the "Tests" pane under the "Test" scheme? Also you can tap on those hollow circles to run them individually. – Arie Litovsky Sep 27 '13 at 20:51
  • The same is valid for iOS devices too – voromax Sep 27 '13 at 21:09
  • I agree this is the answer, but I've not been able to find anything in Apples documentation that says this. Does anyone know where this dependency is documented? – maxpower Sep 30 '13 at 16:51
  • 3
    @maxpower Relevant documentations: "[The new XCTest testing framework ... **works for iOS 7 and later**...](https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_5_0.html#//apple_ref/doc/uid/TP40012953-SW21)" and "[XCTest **does not support iOS 6 destinations**.](https://developer.apple.com/library/mac/releasenotes/DeveloperTools/RN-Xcode/#//apple_ref/doc/uid/TP40001051-SW284)" – Pang Jan 15 '14 at 07:45
  • Same problem with XCode 6 and iOS 8.0. You must run your tests on the iOS 8.0 simulator. I used iPhone 5s (8.0). – Nick N Oct 06 '14 at 17:42
2

I have fixed this by setting the General Tab -> Deployment Target to 7.0 (for the app that you are using to "run" the unit tests). This is not great if you want to support earlier than 7.0 for your main App. But since there is no Deployment Target on the unit test build target you cannot set it there. You instead have to set the Target of the unit tests (on General tab) to the App whose Deployment Target is 7.0. You can setup a "TestApp" to do this so you don't have to restrict your main app's deployment.

0

I had the exact same problem although my CI server was configured with Xcode 5.1.1 and iOS 7.1. I tried many parameters, finally the right one was -destination.

Here's an example of a full command:

xcodebuild -workspace MyApp.xcworkspace -sdk iphonesimulator7.1 -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" -scheme MyAppTests test

It also works with xctool 0.1.16.

Credits: http://www.mokten.com/2014/04/xcodebuild-unit-tests-library-not-loaded-no-image-found/

One detail that may explain why I had to add the -destination param, is that I have both iOS 6 and 7.1 SDKs installed. I haven't checked what happens if I delete the iOS 6 SDK though.

HTH

Philippe A
  • 1,252
  • 9
  • 22