XCTestCase waitForExpectationsWithTimeout: handler: throws EXC_BAD_ACCESS when the wait fails

I am testing an asynchronous call using XCTestExpectation.

The following code works (the test succeeds) when executeHandler is executed before the specified 1 second timeout.

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) } 

However, if the Handler termination is not called, and therefore the wait is not fulfilled, instead of getting a test failure when calling waitForExpectationsWithTimeout, I get EXC_BAD_ACCESS, which is not very convenient, since it makes it impossible to view the results of the entire test suite.

How can I avoid this and get a normal test failure?

+6
source share
1 answer

It appears that when creating the wait, EXC_BAD_ACCESS passes the description to nil.

Passing any string to this call makes it work, and we get the expected test failure when the wait fails.

 let expectation: XCTestExpectation = self.expectationWithDescription("...") 
+4
source

Source: https://habr.com/ru/post/980003/


All Articles