I am trying to write an iOS app using TDD and the new XCTest framework. One of my methods retrieves a file from the internet (given a NSURL object) and stores it in the user
To access to the local file :
NSURL*imageUrl=[[NSBundle mainBundle]URLForResource:@"imageName" withExtension:@"png"];
You can make asynchronous access and wait for the response using : https://github.com/travisjeffery/TRVSMonitor
If you have added : dataset1.json
in the test target (2) :
NSString *p=[[NSBundle mainBundle] pathForResource:@"dataset1" ofType:@"json"];
NSLog(@"%@",p);
2013-10-29 15:49:30.547 PlayerSample[13771:70b] WT(0): /Users/bpds/Library/Application Support/iPhone Simulator/7.0/Applications/7F78780B-684A-40E0-AA35-A3B5D8AA9DBD/PlayerSample.app.app/dataset1.json
In fact, the [NSBundle mainBundle]
when running a UnitTest is not the path of your app, but is /Developer/usr/bin, so this will not work.
The way to get resources in a unit test is here: OCUnit & NSBundle
In short, use:
[[NSBundle bundleForClass:[self class]] resourcePath]
or in your case:
[[NSBundle bundleForClass:[self class]] resourceURL]