加载 XCTest 中的测试资源而不使用 Bundle

huangapple go评论54阅读模式
英文:

Loading test resources without Bundle in XCTest

问题

I have translated the code part for you:

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

If you need further assistance, please let me know.

英文:

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?

答案1

得分: 0

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.

英文:

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.

huangapple
  • 本文由 发表于 2023年7月6日 21:31:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629391.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定