With Xcode 6, Apple have finally given us a sanctioned way to perform asynchronous unit tests. For more information about this you can watch the WWDC 2014 session Testing in Xcode 6 or read the new Testing with Xcode document.
Both of these show you how to adopt the new methods in Xcode 6, however some of us still need to build with Xcode 5.1 in the hope that we’ll ship before Xcode 6 is released, but may still want to test asynchronous methods now.
Previously, I’ve used techniques similar to Mike Ash’s NSRunLoop-based example to cause the test to wait for my async code to finish running, which has worked well. Using this approach, I have recreated the basics of Apple’s asynchronous XCTest methods in a project called DCTAsynchronousTesting.
The following shows how you would use this code, it might look extremely similar to examples from Apple’s documentation.