xcode - 如何将 XCTest 标记为挂起?

标签 xcode unit-testing tdd xctest

我有一个 XCTestCase 的子类,我想将一些测试标记为 pending,就像使用 RSpec 一样

https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/pending/pending-examples

最佳答案

没有简单的方法可以做到这一点。最实用的解决方案是注释掉或重命名您的测试:

@implementation MyTestCase

- (void)testSomething { /* ... */ }

// Option 1: Comment out the test.
// - (void)testSomething { /* ... */ }

// Option 2: Rename the test such that XCTest does not consider 
// it a valid test method. In order to be "valid", it needs to:
// 
// - Have a return type of `void`
// - Take no parameters
// - Begin with "test"
//
// Here, we rename the test so that it does not begin with "test".
- (void)PENDING_testSomething { /* ... */ }

@end

当然,RSpec 的优点之一是它会打印出某种警告。您可以使用 #warning 自行添加:

#pragma Pending!
- (void)PENDING_testSomething { /* ... */ }

这会在 Xcode 中显示警告。请记住,#warning 仅适用于 Objective-C,不适用于 Swift。

测试框架,如 QuickSpecta提供挂起的例子:

pending("tests something") { /* ... */ }
xit("tests something") { /* ... */ }
xdescribe("describes something") { /* ... */ }
xcontext("provides context for something") { /* ... */ }

这些测试框架通过覆盖 -[XCTestCase testInvocations] 来防止运行“挂起”测试。这样做需要做很多工作,但如果您想自己实现“待定测试”,您也可以考虑这样做。

关于xcode - 如何将 XCTest 标记为挂起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32825417/

相关文章:

ios - 在 iPhone 上将整个 pdf 页面解析为 NSString

flutter - 单元测试 GetxController

php - 模拟 CakePHP 的 HttpSocket 类

java - 如何在 Wicket 中测试链接的文本

安卓 TDD : The saga continues with Robolectric & Gradle

iphone - iOS:横向到纵向调整大小不完整

iphone - 导航中上一个屏幕的导航 Controller 和标题?

python脚本在sublime text中打开文件

unit-testing - Jest – 如何模拟模块中的非默认导出?

c++ - 从外部调用静态 C 函数