O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

For the More Curious: Asynchronous Testing

Suppose that you want to test a method like the following:

f​u​n​c​ ​d​o​W​o​r​k​I​n​B​a​c​k​g​r​o​u​n​d​W​i​t​h​C​o​m​p​l​e​t​i​o​n​(​c​o​m​p​l​e​t​i​o​n​H​a​n​d​l​e​r​:​ ​(​B​o​o​l​,​ ​N​S​E​r​r​o​r​?​)​ ​-​>​ ​(​V​o​i​d​)​)​

This method takes a completion handler which returns asynchronously, sometime after the function returns. You would like to test that this function does eventually call its completion handler, and that when the completion handler is called, it is passed true for its first argument, and nil for its second. The techniques that have been discussed so far in the chapter do not allow for testing this method. For testing an asynchronous method, XCTest provides XCTestExpectation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required