XCTestCase for CoreData fails with "could not locate the entity for myappTests.Example"

Viewed 398

Where I can create an entity like so inside an XCTestCase test just fine:

let entity = NSEntityDescription.insertNewObject(
                   forEntityName: String(describing: Example.self), 
                   into: inMemoryManagedObjectContext)

But if I do it like this:

let item = Example(context: inMemoryManagedObjectContext)

A test would fail with...

failed: caught "NSInvalidArgumentException", "An NSManagedObject of
class 'myappTests.Example' must have a valid NSEntityDescription."

How am I supposed to test Core Data objects if I can't create them the way it is usually done?

1 Answers
Related