Summary

In this chapter, we wrote tests using test expectations provided by XCTest. We also used stubs to fake a server. We took a look at how both ways bring us closer to our goal: a finished app with as few bugs as possible.

We used dependency injection to catch the completion handler of the session data task in our fake URL session. This way, we could feed test data into the implementation code and assert that the code is implemented as expected. As we controlled the data that the completion handler received, we were able to simulate all kinds of errors and drive the implementation of the correct error handling.

Using the keychain access as an example, we took a look at how to write tests for features that are yet to be implemented.

In the following ...

Get Test-Driven iOS Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.