views:

27

answers:

1

When i run unit tests it fails on loading external resources (images) with the same error as if they don't exist. In xcode i have added the resources to the unit test target. I don't know what to try next.

I am using the Cocos2d framework, I try to load the following code within a unit test AtlasSpriteManager *at = [AtlasSpriteManager spriteManagerWithFile:@"player2.png" capacity:50];

It seems this actually calls UIImage imageWithContentsOfFile which returns nil.

The actual code that throws the error looks like

image = [uiImage CGImage]; if(image == NULL) { [self release]; NSLog(@"Image is Null"); return nil; }

It seems that the images required are not copied over to the Application Support directory before the unit tests run, only after a successful pass. I am not sure if this is the problem, but if it is is there a way to change the build order so the images are copied first and the unit tests can find them?

+1  A: 

The resources most likely aren't getting included into the target. So before you have your Run Script phase of your test bundle, make sure you have a "Copy Resources" phase that copies the resources into the test bundle that the tests will need.

Dave DeLong
I regularly fail to include the proper targets for my resources. More than actual code failure, is this that raises alarms.
Pestilence
I do have a copy bundle resource phase. I am following the apple documentation on unit tests, so i have my duplicated project that adds the copy bundle resource PROJNAME.octest, this expanded has the image resources. Then in the unit test bundle target there is also a copy bundle resource phase that contains my images. I am assuming it is before the run script phase as it is higher in the tree when i expand the target.
jacob