Reputation: 26953
I have a project with tests on Xcode 4.3.2, i want to access some files from the tests when they are run. I added the files to the automatically generated "Supporting Files" folder, but i can't access it when the test is run, i will get errors because the file is not found.
I tried these combinations:
myFile
Supporting Files/myFile
../Supporting Files/myFile
None of these worked though. Any idea what i'm doing wrong?
Upvotes: 4
Views: 6143
Reputation: 35636
Once you add them to your Supporting Files
folder, you have to check your test target (target membership) in order for them to be available in the bundle. You can also verify this (along with their location) in your target info under 'build phases'.
Then (inside your tests) you get the path of your files like this:
NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"index" ofType:@"html"]; //Whatever your file - extension is
I attach a screenshot as a quick reference:
PS. The screenshot is from an OSX project but the procedure is identical for iOS
Upvotes: 13