views:

148

answers:

1

I'm trying to unit-test code for loading and querying data from plist file. I'm loading data with code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"availableshops" ofType:@"plist"];
NSArray *arrayOfShops = [[NSArray alloc] initWithContentsOfFile:path];

When testing app in simulator and on the device everything work. BUT when I run unit test, code "[arrayOfShops count]" always returns "0".

I have the same files in "Copy Bundle Resources", "Compile Sources" and "Link Binary With Libraries" for main target and unit-test target. I've also tried with and without main target as "Direct Dipendencies" for unit-test target.

Does anyone have idea what is the problem?

A: 

Are you sure the plist root element is an array? Posting the plist might help.

You could also try this:

NSArray* shopsArray = [NSArray arrayWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"availableshops.plist"];
Shaun