【发布时间】:2015-02-19 20:27:21
【问题描述】:
我正在使用 XCTestExpectation 测试异步调用。
当completionHandler在给定的1秒超时之前执行时,以下代码有效(测试成功)。
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)
}
但是,如果没有调用completionHandler,因此期望没有实现,而不是在调用waitForExpectationsWithTimeout时得到一个测试失败,我得到一个EXC_BAD_ACCESS,这不是很方便,因为这使得不可能看到整个测试套件结果.
我怎样才能避免这种情况并获得正常的测试失败?
【问题讨论】:
标签: ios xcode swift xctest xctestexpectation