Implementing tests using a web service
In the previous chapter, we wrote a stub for CLGeocoder
. Now, we will write a test that asserts that the geocoder built into CoreLocation
works as we expect it to. The fetching of coordinates from a geocoder is asynchronous. This means that we have to write a test that can deal with asynchronous interfaces.
Let's first structure the files a bit in the Project Navigator of Xcode. Select all the controller files in the main target (ItemListViewController.swift
, ItemListDataProvider.swift
, ItemCell.swift
, DetailViewController.swift
, and InputViewController.swift
), and press ctrl + click to create a group from the selection. Let's call this group Controller
. Do the same with the corresponding test cases in the test target.
Now, let's get started with the test. We start naively by adding the following test to InputViewControllerTests
:
func test_Geocoder_FetchesCoordinates() { let address = "Infinite Loop 1, Cupertino" CLGeocoder() .geocodeAddressString...