Search code examples
objective-cxcodexcode-ui-testingnsbundle

Can't get path of image in NSBundle?


I am trying to get the path of an image while UITesting. I've tried multiple ways as shown under here, but none are working?

Name of image file is: TestImage.fff

NSBundle* testBundle = [NSBundle bundleForClass: [self class]];
NSString* testImage = [testBundle pathForResource:@"TestImage.fff" ofType:@"fff"];
NSString* testImage2 = [testBundle pathForImageResource:@"TestImage"];
NSURL* testImage3 = [testBundle URLForResource:@"TestImage" withExtension:@"fff"];

Can someone tell me where I am going wrong?


Solution

  • Inside XCode, select your test target inside the target list. Then select the Build Phases tab and inside the Copy Bundle Resources phase, add the required resources.

    Example of project