When the unit test harness runs your code, your unit test bundle is NOT the main bundle. Your code is searching the wrong bundle. If you replace the above line with:
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"foo" ofType:@"txt"];
Then everything will be fine.