Implementing asynchronous tests
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.
But 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 control + left-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 naïvely. Add the following test to InputViewControllerTests
:
func test_GeocoderWorksAsExpected() { CLGeocoder().geocodeAddressString("Infinite Loop 1, Cupertino...