Search code examples
xcodexctest

Loading test resources without Bundle in XCTest


I've a static library with a corresponding test target. The test target doesn't use a "Host Application". Within the test target, I've some test files in the folder TestResources, which I'd like to load.

The resources are copied, I see them in ~/Library/Developer/Xcode/DerivedData/<workspace>/Build/Products/<schema>-iphonesimulator/myLibraryTests.xctest/TestResources/.

But

[[NSBundle bundleForClass:[self class]] URLForResource:@"TestResources/test" withExtension:@"json"];

doesn't work. There are no bundles at all! [NSBundle allBundles] returns nil.

So what can I do to get the path to my resources?


Solution

  • The bundle is there and the resources can be loaded!

    Xcode gave me a false lead. I don't know why, but in the debug area, all variables are nil, despite "Debug executable" is enabled in the schema.