Core Data Basics: Testing

Yeah, testing is important

Image for post
Image for post
Photo by Andriyko Podilnyk on Unsplash

Prerequisites:

Terminology

Why test

The example App

The setup

Image for post
Image for post

The App setup: make it testable with a protocol

Image for post
Image for post
Click for Gist
Image for post
Image for post
Click for Gist
Image for post
Image for post
Click for Gist
Image for post
Image for post
Click for Gist

The setup for the tests

Image for post
Image for post
Click for Gist
Image for post
Image for post
Click for Gist
Image for post
Image for post
Click for Gist
Image for post
Image for post
Click for Gist

The tests

Get the task from our mocked CoreDataManager

Image for post
Image for post
Click for Gist

Get a saved task from our mocked CoreDataManager

Image for post
Image for post
Click for Gist

Use the production CoreDataManager — but inject an entity

Image for post
Image for post
Click for Gist

Conclusion

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store