ios - 将测试目标的 'Host Application' 设置为 None,然后无法找到捆绑资源

标签 ios unit-testing storyboard xctest nsbundle

在将 Host Application 设置为 none 之前,我的单元测试中有这行代码,没有给我任何问题。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];

将它设置为 None 后,我得到了这个错误。

<unknown>:0: failed: caught “NSInvalidArgumentException”, “Could not find a
storyboard named ‘Main’ in bundle NSBundle 
</Applications/Xcode.app/Contents/Developer/Platforms/
iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/Developer/usr/bin> (loaded)”

我找到了 this post这给了我解决方案。我只是指定了我正在加载 View Controller 的类的包。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" 
bundle:[NSBundle bundleForClass:[self class]];

我只是想知道为什么会这样。当我删除导致主包中的资源被排除的主机应用程序时会发生什么?

最佳答案

没关系,我想出了原因。 mainBundle 的文档说

Returns the NSBundle object that corresponds to the directory where the current application executable is located.

自从我删除主机应用程序后,我的项目找不到主包目录,因为没有应用程序可执行文件。

关于ios - 将测试目标的 'Host Application' 设置为 None,然后无法找到捆绑资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38476885/

相关文章:

unit-testing - Kotlin 中的测试无法访问 protected 方法

ios - 如何将表数据源和委托(delegate)导出链接到 UITableViewController?

xcode - Swift:通过代码更改 Storyboard上元素的位置

ios - iphone map 套件在室内?

Angular Testing - 无法在订阅内运行断言

java - Controller Java 上的 Spring 单元测试

ios - 在 instantiateViewControllerWithIdentifier 之后 dealloc

ios - 如何在 swift3 中从 Any 获取字符串

ios - 如何返回到不同 Storyboard的上一个 View Controller ?

ios - 使用它的 indexPath.row 更改单元格图像