Improve Mock Object Reporting
We can improve the reporting from our mock object in different ways. Right now, the verify method checks the call count is 1. It goes on to check the first URL argument, regardless of the call count.
Let’s see the current failure reporting by introducing errors to ViewController. First, in the buttonTapped method, comment out the call to searchForBook(terms:). Run tests. You’ll see two errors:
| XCTAssertEqual failed: ("0") is not equal to ("1") - call count |
| XCTAssertEqual failed: ("nil") is not equal to ("Optional( |
| https://itunes.apple.com/search?media=ebook&term=out%20from%20boneville)") |
| - request |
When the method is never called, it’s kind of odd to report a mismatch on the URL argument.
Next, restore ...
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.