【发布时间】:2015-12-25 20:07:15
【问题描述】:
我有一个XCTestCase 的子类,我想将一些测试标记为pending,就像使用 RSpec 一样
https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/pending/pending-examples
【问题讨论】:
标签: xcode unit-testing tdd xctest
我有一个XCTestCase 的子类,我想将一些测试标记为pending,就像使用 RSpec 一样
https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/pending/pending-examples
【问题讨论】:
标签: xcode unit-testing tdd xctest
没有简单的方法可以做到这一点。最实用的解决方案是注释掉或重命名您的测试:
@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。
pending("tests something") { /* ... */ }
xit("tests something") { /* ... */ }
xdescribe("describes something") { /* ... */ }
xcontext("provides context for something") { /* ... */ }
这些测试框架通过覆盖-[XCTestCase testInvocations] 来防止运行“待定”测试。这样做需要做很多工作,但如果您想自己实现“待定测试”,您也可以考虑这样做。
【讨论】:
它并不完全是待定的,但如果您的领导认为待定测试是一个失败的套件(我是我团队的负责人,我确实如此),那么简单的 XCTFail() 就可以完成这项工作:
#pragma mark - Something Tests
- (void)testSomething_scenario_result {
XCTFail(@"Pending Test: %@",NSStringFromSelector(_cmd));
}
然后,如果您出于任何原因(可能是个人开发分支)需要保留未决测试,那么您可以轻松查看哪些失败是相关的,但在您完成之前整个套件仍然失败。
对于“真”待处理,modocache 的回答要完整得多。
【讨论】: