XCTestExpectation Gotchas
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
February 2, 2017 3:03 PM
[…] XCTestExpectation Gotchas, Xcode 6.0.1 Asynchronous Tests, XCTestCase / XCTestExpectation / […]