Challenge: Test Invalid JSON Dictionary

The first challenge in Chapter 28 was to improve the handling of faulty JSON by ScheduleFetcher’s courseFromDictionary(_:) method.

In this chapter, you only tested that the method behaved correctly when it was provided with valid JSON. Create another test where you pass invalid JSON to the method. Assert that the Course object that is returned is nil.

Think about how much easier it would have been to complete the original challenge if you were able to run your new unit test that passes invalid JSON to courseFromDictionary(_:) as you were implementing the method. Having tests makes writing code easier!

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.