NSInvalidArgumentException in my unit tests after adding attributes and changing types

I'm experiencing an issue where I get an error for all of my core data tests since updating my core data model file. I added attributes to some models and changed the types of some existing attributes. No other changes were made and the tests passed prior to making this change. Now, any time I initialize a core data object in my unit tests, I get the following exception:

caught "NSInvalidArgumentException", "An NSManagedObject of class 'Address' must have a valid NSEntityDescription."

'Address' changes depending on the class being instantiated, but regardless, any test that involves creating a class inheriting from NSManagedObject fails at this point, regardless of if the model was one of the classes that had attributes added or modified.

This only fails in the unit tests. CoreData still works as expected and does not throw exceptions at run time. The exceptions are present even when checking out the code fresh or when running the unit tests on a separate machine (on our Travis CI server for instance). The exceptions occur when running the tests immediately after resetting the simulator. This app hasn't launched and is still in development so I only have 1 model version and no migrations to worry about.


Has anyone else run into this? Do you have any idea for the cause or a workaround? The entity names have not changed and neither has the name of my xcdatamodeld file. Both of those seem to be the first place to look when this issue arrises.


My environment:

  • macOS 10.12.6
  • Xcode 9.1


I will happily post code to help narrow in, I just don't know what would be relevant at this point. Let me know if there's something you'd like to see.