Saturday, April 26, 2014

Unit Testing Asynchronous Cocoa

Drew McCormack:

There are two aspects to testing an asynchronous task that you need to consider. The first is that the unit test method should not return until the asynchronous task has fully completed; otherwise, the test will terminate prematurely. The second, which relates only to unit tests of Cocoa code, is to keep the main run loop turning over. Without the run loop, functionality such as networking and timers will not work.

The way I run asynchronous operations in unit tests for Ensembles is to include two methods in the test class. The first starts the run loop, and does not return until the run loop is stopped.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment