This looks like exactly what you need:
XCAsyncTestCase: Asynchronous capable SenTestCase subclass.
Basically, you should write your test like this:
- (void)testConnection
{
[[Conector sharedInstance] performAsynchronousRequestWithServerRequest:_srvRequest completionHandler:^(RequestAsynchronousStatus finishStatus, NSData *data) {
if (finishStatus == RequestAsynchronousOK)
{
_data = data;
[self notify:XCTAsyncTestCaseStatusSucceeded];
NSLog(@"Data OK");
}
}];
[self waitForTimeout:10];
XCTAssertNotNil(_data, @"Data was nil");
}
Notice the waitForTimeout:
call and the notify:
calls. 10 seconds should be enough for the test, though it would depend on the request itself.
You could even get more specific and wait for a certain status, like so:
[self waitForStatus: XCTAsyncTestCaseStatusSucceeded timeout:10];
This way, if the connection fails to notify the XCTAsyncTestCaseStatusSucceeded
status, the wait call will timeout and your test would fail (as it should).