Accessing a UIImage inside a OCUnit test target

Since iOS 8 we have the: -imageNamed:inBundle:compatibleWithTraitCollection: failable init on UIImage

In Swift:

let bundle = NSBundle(forClass: self.dynamicType)
let image:UIImage? = UIImage(named: "imageFileName",
                          inBundle:bundle,
     compatibleWithTraitCollection:nil)

In Objective-C

NSBundle* bundle = [NSBundle bundleForClass:[self class]];
UIImage* image = [UIImage imageNamed:@"imageFileName.extension"
                             inBundle:bundle
        compatibleWithTraitCollection:nil];

Documentation


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];