Testing asynchronous block of code
suggest change- (void)testDoSomethingThatTakesSomeTime{
XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Long method"];
[self.someObject doSomethingThatTakesSomeTimeWithCompletionBlock:^(NSString *result) {
XCTAssertEqualObjects(@"result", result, @"Result was not correct!");
[completionExpectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0 handler:nil];
}
- Feed the dummy data to the method under test if required.
- The test will pause here, running the run loop, until the timeout is hit or all expectations are fulfilled.
- The timeout is how long the test waits for the asynchronous work to respond.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents