【问题标题】:Testing without simulator using xctool使用 xctool 在没有模拟器的情况下进行测试
【发布时间】:2016-07-06 10:18:14
【问题描述】:

我正在尝试使用 xctool 在没有模拟器的情况下运行单元测试。我按照this comment 的指示,在测试目标的常规选项卡中将“主机应用程序”设置为无。

当我运行 xctool -project MyProject.xcodeproj/ -scheme MyProject test 时,我得到了这个错误。

<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)"

我确保 Main.storyboard 是测试目标的成员。为什么会发生这种情况,我该如何解决?

【问题讨论】:

    标签: objective-c xcode unit-testing xcode-storyboard xctool


    【解决方案1】:

    想通了,this post 帮助了。

    我的测试用例设置方法像这样初始化故事板

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:DEVMainStoryboardName 
    bundle:nil];
    

    问题是将 nil 传递给 bundle 参数,该参数使用的是不是在测试目标中使用的主包——所以你必须通过编写来指定你想要使用测试包

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:DEVMainStoryboardName 
    bundle:[NSBundle bundleForClass:[self class]]];
    

    然后不要忘记将情节提要作为目标的成员。

    【讨论】:

      猜你喜欢
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      • 2023-01-08
      • 2019-07-27
      相关资源
      最近更新 更多