Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode, accessing files in "Supporting Files" folder during tests

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?

like image 828
lurscher Avatar asked Dec 12 '22 01:12

lurscher


1 Answers

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: Target membership

PS. The screenshot is from an OSX project but the procedure is identical for iOS

like image 133
Alladinian Avatar answered Dec 14 '22 23:12

Alladinian