NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

New Core Data Stack (PersistenceController) in Unit Tests

Forums > SwiftUI

With the new Swift App Xcode template, I see the PersistenceController struct was added with a shared and preview instance to serve as the Core Data stack. From what I understand, the preview instance is for SwiftUI previews.

If I have a service class that takes an instance of my Core Data stack, should I be using the preview instance as part of my unit tests? Or should I create some sort of spy/fake to pass into the service class I am testing?

In general, what is the best practices for testing classes that use Core Data?

   

Hacking with Swift is sponsored by NSSpain

SPONSORED Announcing NSSpain 2020: Remote Edition! An online, continuous conference for iOS developers. We’ll start on Thursday and finish on Friday, with talks, activities, and lots of fun for 36 hours, non-stop. Sound good? Join us!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.