Fortunately, this is where Xcode 6′s asynchronous testing comes in. It allows us to create
XCTestExpectationobjects, which are not tests but timers. We create expectations withXCTestCase’sexpectationWithDescription(), which just takes a string to describe what we’re waiting for. Then, prior to the end of thetest…method, we callwaitForExpectationsWithTimeout(), passing in a timeout period and a completion handler closure. This prevents the test method from exiting until either the timeout expires, or some asynchronous test code callsfulfill()on the expectation object, which unblocks it.
Update (2014-07-22):Mattt Thompson:
Perhaps the most exciting feature added in Xcode 6 is built-in support for asynchronous testing, with the
XCTestExpectationclass. Now, tests can wait for a specified length of time for certain conditions to be satisfied, without resorting to complicated GCD incantations.
CocoaProgrammingSwift Programming LanguageTesting
Black Friday
Blog
Archives
Tag Cloud
Top Posts
Recently Updated
RSS Feed ·Comments
Mastodon ·Twitter
Apple News
Trackback
Support this site viaPatreon.
Try my Mac apps: