New Core Data Stack (PersistenceController) in Unit Tests

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?
Testing units together is called integration testing. Just add another instance to the PersistenceController that uses an in-memory store the same as the preview instance. You can make methods to add sample data and call them depending on what you would like in each.
New Core Data Stack (PersistenceController) in Unit Tests
 
 
Q