Thursday, March 24, 2016 [Tweets]

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.

Comments

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

Leave a Comment