Promote the Test Spy into a Mock Object
Our test case makes two assertions against the test spy:
| XCTAssertEqual(mockURLSession.dataTaskCallCount, 1, "call count") |
| XCTAssertEqual( |
| mockURLSession.dataTaskArgsRequest.first, |
| URLRequest(url: URL(string: "https://itunes.apple.com/search?" + |
| "media=ebook&term=out%20from%20boneville")!), |
| "request") |
It’s saying, “Confirm that system under test called the dataTask method once, with this request as the argument.” Let’s get a sense for how these assertions report failures. Go to the production code for the button tap action:
| @IBAction private func buttonTapped ... |
Get iOS Unit Testing by Example 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.