If we have a test that has to kick off an asynchronous task, whether it runs in another thread or in the main thread’s runloop, how do we test it?
Good news is:
With Xcode 6, Apple has added test expectations to the XCTest framework in the form of the XCTestExpectation class. When we instantiate a test expectation, the testing framework expects that it will be fulfilled at some point in the future.
And just how does this relate to an asynchronous task?
Our test code fulfills the expectation in the completion block with a call to the XCTestExpectation method fulfill.