iOS测试:有没有跳过测试的方法? [英] iOS Testing: Is there a way to skip tests?

查看:98
本文介绍了iOS测试:有没有跳过测试的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果该功能当前被禁用,我不想执行某些测试.有没有一种方法可以跳过"测试(并在控制台上获得适当的反馈)?

I don't want to execute certain tests if the feature is currently disabled. Is there a way to "skip" a test (and to get appropriate feedback on console)?

类似这样的东西:

func testSomething() {
  if !isEnabled(feature: Feature) {
    skip("Test skipped, feature \(feature.name) is currently disabled.")
  }

  // actual test code with assertions here, but not run if skip above called.
}

推荐答案

您可以通过右键单击左侧编辑器托盘中的测试符号来禁用Xcode运行的XCTest.

You can disable XCTests run by Xcode by right clicking on the test symbol in the editor tray on the left.

您将获得此菜单,然后可以选择禁用"选项.

You'll get this menu, and you can select the "Disable " option.

再次右键单击将允许您重新启用.另外,如用户@sethf的回答所述,您还会在.xcscheme文件中看到当前禁用的测试的条目.

Right clicking again will allow you to re-enable. Also, as stated in user @sethf's answer, you'll see entries for currently disabled tests in your .xcscheme file.

最后,我建议不要在xcscheme中禁用测试并提交禁用代码.测试注定会失败,而不是因为不方便而被静默.

As a final note, I'd recommend against disabling a test and committing the disabling code in your xcscheme. Tests are meant to fail, not be silenced because they're inconvenient.

这篇关于iOS测试:有没有跳过测试的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆