Thursday, March 24, 2016 [Tweets] [Favorites]

XCTestExpectation Gotchas

Jeremy W. Sherman:

XCTestExpectation simplifies testing callback-style code, but some of its design choices make tests using it fragile unless they’re mitigated:

  • It explodes if everything works right but later than you expected.
  • It explodes if everything works right more than once.

This article presents two concrete mitigations:

  • Use weak references to ensure the expectation dies before it can cause you trouble.
  • Use a different promise API to do your waiting.

1 Comment

[…] XCTestExpectation Gotchas, Xcode 6.0.1 Asynchronous Tests, XCTest​Case / XCTest​Expectation / […]

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

Leave a Comment