我有一个 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。
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/