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.

In the following chapter, we will put the different parts of the last few chapters together and finally see the app running.