{"id":190,"date":"2008-12-22T20:37:34","date_gmt":"2008-12-23T01:37:34","guid":{"rendered":"http:\/\/vgable.com\/blog\/2008\/12\/22\/resources-in-unit-tests-and-other-frameworks\/"},"modified":"2008-12-22T20:37:36","modified_gmt":"2008-12-23T01:37:36","slug":"resources-in-unit-tests-and-other-frameworks","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2008\/12\/22\/resources-in-unit-tests-and-other-frameworks\/","title":{"rendered":"Resources in Unit Tests and Other Frameworks"},"content":{"rendered":"<p>To load a resource inside a unit test or other bundle, do:<\/p>\n<p><code>NSBundle *unitTestsBundle = [NSBundle bundleForClass:[self class]];<br \/>\nNSString *pathToResource = [unitTestsBundle pathForResource:<i>name<\/i> ofType:<i>fileExtension<\/i>];<br \/><\/code><\/p>\n<p><code>[NSBundle mainBundle]<\/code> points to the bundle for the current executable, so it&#8217;s handy in an <em>application<\/em> (where it will point to your .app bundle).  But since unit tests are loaded into another program or test-harness to run, it&#8217;s not appropriate to use it in a unit test.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To load a resource inside a unit test or other bundle, do: NSBundle *unitTestsBundle = [NSBundle bundleForClass:[self class]]; NSString *pathToResource = [unitTestsBundle pathForResource:name ofType:fileExtension]; [NSBundle mainBundle] points to the bundle for the current executable, so it&#8217;s handy in an application (where it will point to your .app bundle). But since unit tests are loaded into [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,6,3,5,4,13],"tags":[269,267,268,254,134],"class_list":["post-190","post","type-post","status-publish","format-standard","hentry","category-bug-bite","category-cocoa","category-macosx","category-objective-c","category-programming","category-sample-code","tag-frameworks","tag-nsbundle","tag-ocunit","tag-unit-testing","tag-xcode"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}