I am doing iOS unit testing using XCTestCase and I am getting a crash due to "unrecognized selector" on async web service handler which returns manipulated NSDictionary by means of completionHandler block.
The crash is not my expectation for assertion statement (XCTAssertNoThrows) and i want to see the failure for this assertion due to crash but the test method which i have written is stopped execution and ends without any test result (Pass/Fail).
- (void)testMethod
{
XCTestExpectation *expectation = [self expectationWithDescription:@"Task longer than timeout"];
[serviceHandler getInfoCompletionHandler:^(NSDictionary *infoDict){
NSString *value = infoDict[@"Key"];
XCTAssert(value.length > 0, @"Value should not be empty.");
[expectation fulfill];
} failure:^(NSError *error){
NSLog(@"Error: %@",error);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:^(NSError *error){
if (error) {
NSLog(@"Error: %@",error);
}
}];
}
Unfortunately, the service handler code is not isolated to do proper unit testing. Since it is not isolated, @try...@catch is not catching NSInvalidArgumentException and it is useless. Mostly likely, i want to implement top level NSSetUncaughtExceptionHandler, but i don't know how to fail the associated test from NSSetUncaughtExceptionHandler.