Thursday, March 24, 2016

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 RSS · Twitter

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

Leave a Comment