April 2015
Intermediate to advanced
556 pages
17h 47m
English
Suppose that you want to test a method like the following:
func doWorkInBackgroundWithCompletion(completionHandler: (Bool, NSError?) -> (Void))
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.
You create an XCTestExpectation from within a test case using XCTestCase ...
Read now
Unlock full access