Challenge: Improve Test Coverage of Web Service Responses

In ScheduleFetcherTests, you currently only have a single test (testResultFromValidHTTPResponseAndValidData(_:)) against ScheduleFetcher’s method resultFromData(_:response:error:). This test verifies the behavior of the method when it is passed valid JSON data and an OK (200) HTTP response.

Write two more tests against resultFromData(_:response:error:). In the first test, call the method with a 404 response and no data. In the second test, call the method with a 200 response and invalid JSON data.

Invalid JSON data here means data that cannot be used by NSJSONSerialization. One way to create invalid JSON data is by turning a string into data:

l​e​t​ ​i​n​v​a​l​i​d​J​s​o​n​D​a​t​a​S​t​r​i​n​g​ ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide 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.