Unit Testing Core Data in iOS

Testing code is a crucial part of app development, and Core Data is not exempt from this. This tutorial will teach you how you can test Core Data. By Graham Connolly.

4.4 (18) · 1 Review

Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Where to Go From Here?

You can download the completed project files by clicking the Download Materials button at the top or bottom of the tutorial.

In this tutorial, you learned how to:

  • Write a testable Core Data stack using an in-memory store.
  • Write a test for existing and new functionality.
  • Test asynchronous code.
  • Apply the Test Driven Development (TDD) methodology.

For a challenge, try writing a test, or a couple of tests, to prevent adding non-negative numbers for numberTested, numberPositive and numberNegative.

If you enjoyed this tutorial, check out iOS Test-Driven Development by Tutorials. You’ll take a deep dive into how to write maintainable and sustainable apps by writing your tests first or adding tests to already-written apps. You should also check out Test Driven Development Tutorial for iOS: Getting Started.

If you’d like to learn more about Core Data, check out Core Data by Tutorials. In this book, you’ll master Core Data in iOS using Swift. Or check out the Getting Started with Core Data Tutorial.

If you have any questions or comments, join the forum discussion below.