XCTestCase waitForExpectationsWithTimeout:处理程序:在未满足期望时抛出EXC_BAD_ACCESS

我正在使用XCTestExpectationtestingasynchronous调用。

在给定的1秒超时之前执行completionHandler时,以下代码工作(testing成功)。

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时得到一个testing失败,我得到一个EXC_BAD_ACCESS,这是不是很方便,因为这使得不可能看到整个testing套件的结果。

我怎样才能避免这种情况,并得到正常的testing失败?

看起来是什么导致EXC_BAD_ACCESS在创build期望时传递一个零描述。

传递任何string到这个调用使它的工作,我们得到预期的testing失败,当期望没有履行。

 let expectation: XCTestExpectation = self.expectationWithDescription("...")