e19*_*985 7 xcode ios xctest swift xctestexpectation
我正在使用XCTestExpectation测试异步调用.
在给定的1秒超时之前执行completionHandler时,以下代码有效(测试成功).
func test__async_call() {
// prepare
let sut = ClassToTest()
let expectation: XCTestExpectation = self.expectationWithDescription(nil)
// test
sut.methodToTestWithCompletionHandler() { () -> () in
expectation.fulfill()
}
// verify
self.waitForExpectationsWithTimeout(1, handler: nil)
}
Run Code Online (Sandbox Code Playgroud)
但是,如果没有调用completionHandler,因此没有满足期望,而是在调用waitForExpectationsWithTimeout时没有得到测试失败,我得到一个EXC_BAD_ACCESS,这不是很方便,因为这使得无法看到整个测试套件的结果.
如何避免这种情况并获得正常的测试失败?
似乎导致 EXC_BAD_ACCESS 的原因是在创建期望时传递了零描述。
将任何字符串传递给此调用都会使其工作,并且当未满足期望时,我们会得到预期的测试失败。
let expectation: XCTestExpectation = self.expectationWithDescription("...")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2866 次 |
| 最近记录: |