iphoneobjective-cipadunit-testingocunit

Accessing a UIImage inside a OCUnit test target


I'm currently writing an image manipulation test for an iPad app. I have a resources folder inside my unit test target with a photo inside, however when I try to access it using [UIImage imageNamed:@"photo1.jpg"] no image gets returned. If I change the file name to one in the main Resources folder an image does get returned.

Is there a way to access the Resources folder inside the unit test target?


Solution

  • Found the answer to this, looks like you can't use [UIImage imageNamed:], you can access the image like this:

    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
    NSString *imagePath = [bundle pathForResource:@"photo1" ofType:@"jpg"];
    UIImage *image = [UIImage imageWithContentsOfFile:imagePath];