O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required