Testing button actions with ViewInspector
The user puts in the address for the to-do item. In the details view of an item, the app shows a map of that location. This means we need to convert the address of the item to a coordinate before we can add the item to the list. Apple provides a GeoCoder
class for that task. We will write tests for fetching an address from a GeoCoder
class in Chapter 10, Testing Networking Code.
In this chapter, we assume that we already have a class called APIClient
that uses GeoCoder
(or some similar service) to translate an address into a coordinate. In the test, we are going to use a mock object for that APIClient
class. Follow these steps to add a protocol for the APIClient
class and a mock conforming to that protocol:
- Select the ToDo group in the project navigator and add a new Swift file with the name
APIClient.swift
. - Add the following protocol definition to that new file:
// APIClient.swift protocol APIClientProtocol { func...