Xcode 目标:来自主目标的图像未加载到测试目标中
Xcode target: Images from main target not loading in test target
所以,我已经开始使用 FBSnapshotTestCase
,一切都按预期工作,除了图像,它没有从包中正确加载。我已经测试过,它们被加载到另一个包中。
查看下面的调试详细信息:
(lldb) po [NSBundle allBundles]
<__NSArrayI>(
NSBundle </Applications/Xcode.app/Contents/.../Xcode/Agents> (loaded),
NSBundle </.../DerivedData/.../ProjectTests.xctest/Frameworks> (not yet loaded),
NSBundle </.../DerivedData/.../ProjectTests.xctest> (loaded)
)
(lldb) po [NSBundle mainBundle]
NSBundle </Applications/Xcode.app/Contents/.../Xcode/Agents> (loaded)
(lldb) po [NSBundle bundleForClass:[self class]]
NSBundle </.../DerivedData/.../ProjectTests.xctest> (loaded)
所以当我 运行 [UIImage imageNamed:@"image"]
它 returns nil
但是当我 运行:
[UIImage imageNamed:@"image" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil]
加载正常。但我无法更改应用程序中的所有图像加载,而且我不知道如何在情节提要中更改它。我试过研究,无法手动设置 mainBundle
.
底线:是否有针对目标的特定配置来为目标设置包,或者是否有创建脚本以将资产移动到正确包的方法?
编辑:
我已验证所有资产都已检查测试目标,并且它们在测试目标的 Copy Bundle Resources
构建阶段内。事实上,它们已加载,但不知何故主包不是我期望的那样
按照 this guide 中的步骤进行操作后,它开始正常工作,但我不得不重新配置一些依赖项。
我缺少的是:
4) Click the Build Settings tab and set the Bundle Loader setting to $(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp
5) Set the Test Host build setting to $(BUNDLE_LOADER)
所以,我已经开始使用 FBSnapshotTestCase
,一切都按预期工作,除了图像,它没有从包中正确加载。我已经测试过,它们被加载到另一个包中。
查看下面的调试详细信息:
(lldb) po [NSBundle allBundles]
<__NSArrayI>(
NSBundle </Applications/Xcode.app/Contents/.../Xcode/Agents> (loaded),
NSBundle </.../DerivedData/.../ProjectTests.xctest/Frameworks> (not yet loaded),
NSBundle </.../DerivedData/.../ProjectTests.xctest> (loaded)
)
(lldb) po [NSBundle mainBundle]
NSBundle </Applications/Xcode.app/Contents/.../Xcode/Agents> (loaded)
(lldb) po [NSBundle bundleForClass:[self class]]
NSBundle </.../DerivedData/.../ProjectTests.xctest> (loaded)
所以当我 运行 [UIImage imageNamed:@"image"]
它 returns nil
但是当我 运行:
[UIImage imageNamed:@"image" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil]
加载正常。但我无法更改应用程序中的所有图像加载,而且我不知道如何在情节提要中更改它。我试过研究,无法手动设置 mainBundle
.
底线:是否有针对目标的特定配置来为目标设置包,或者是否有创建脚本以将资产移动到正确包的方法?
编辑:
我已验证所有资产都已检查测试目标,并且它们在测试目标的 Copy Bundle Resources
构建阶段内。事实上,它们已加载,但不知何故主包不是我期望的那样
按照 this guide 中的步骤进行操作后,它开始正常工作,但我不得不重新配置一些依赖项。 我缺少的是:
4) Click the Build Settings tab and set the Bundle Loader setting to $(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp
5) Set the Test Host build setting to $(BUNDLE_LOADER)