Unit Testing Core Data Models

5 Episodes

Episode 1

04:11

Setting Up the Project

In this series, I show you how to unit test Core Data models. Before we start, though, I'd like to challenge you. How would you unit test a Core Data model? Pause the video for a moment and try to come up with a strategy. Remember what we covered in Core Data Fundamentals. Which ingredients do we need to create an NSManagedObject instance?

Episode 2

07:02

Setting Up the Core Data Stack

Remember from Core Data Fundamentals that we need a managed object context to instantiate a managed object. To freshen up your memory, this is what it takes to create a note.

Episode 3

05:59

Unit Testing a Core Data Model

It's time to write the first unit test for the Note class. The first unit test we write tests the updatedAtAsDate computed property of the Note class. Remember that we only unit test the behavior we add to the Note class. We name the unit test testUpdatedAtAsDate().

Episode 4

11:19

Writing Better Unit Tests

Let's start with the updatedAtAsDate computed property. Change the name of the unit test to testUpdatedAtAsDate_NotNil(). We need to implement a second unit test for the updatedAtAsDate computed property if the updatedAt property doesn't have a value.

Episode 5

05:06

Writing More Unit Tests

It's time to shift gears and focus on the Category class. This shouldn't be difficult since you already know how to write unit tests for a Core Data model and we laid the foundation when we implemented the unit tests for the Note class. Pause the episode for a moment and give it a try.