Xcode Unit Testing - Accessing Resources from the application's bundle? Xcode Unit Testing - Accessing Resources from the application's bundle? xcode xcode

Xcode Unit Testing - Accessing Resources from the application's bundle?


While trying to reproduce your problem it hit me: Have you tried just adding your resources to your test bundle? Would that cause any problems for you? I did exactly that, and it worked great for me. For example:

Code:

- (void)testBundleLoading {  NSLog(@"Main Bundle Path: %@", [[NSBundle mainBundle] bundlePath]);  for (NSBundle *bundle in [NSBundle allBundles]) {    NSLog(@"%@: %@", [bundle bundleIdentifier],                      [bundle pathForResource:@"fire" ofType:@"png"]);  }}

Output:

2010-05-05 14:31:05.961 otest[16970:903] Main Bundle Path: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/Developer/usr/bin2010-05-05 14:31:05.962 otest[16970:903] (null): (null)2010-05-05 14:31:05.963 otest[16970:903] com.freetimestudios.KayakKingTests: /Volumes/FreeTime/KayakKing/build/Debug-iphonesimulator/KayakKingTests.octest/fire.png

I hope this helps.


I ran into this problem with Xcode 4 and my problem was that I had an old Xcode 3 project and somehow the info plist for the test target had gone missing. I added a new UnitTests-Info.plist to the project and I was suddenly able to retrieve resources again.