Skip to content

Logic Tests - Can't find entity #397

Closed
ski081 opened this Issue Jan 25, 2013 · 2 comments

2 participants

@ski081
ski081 commented Jan 25, 2013

I'm running a plain old vanilla iOS logic test bundle (not application tests).

I followed Saul's article on Cocoa is my Girlfriend (http://www.cimgf.com/2012/05/15/unit-testing-with-core-data/) to set up the core data stack in memory. I get through the setup method, and it looks like the core data stack is ready to go.

I can print out a description of my model, and it includes the Person object. But when I try to run [Person createEntity], I get this:

+entityForName: could not locate an entity named 'Person' in this model

it's failing on:

+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_

I've got my core data model being compiled as ppart of my unit test bundle, but it can't find the entity.

For completeness, here are my setUp, tearDown, and test methods from my test class:

-(void)setUp{
    [MagicalRecord setDefaultModelFromClass:[self class]];
    [MagicalRecord setupCoreDataStackWithInMemoryStore];
}

-(void)tearDown{
    [MagicalRecord cleanUp];
}

-(void)testPerson{
    // This is where it fails
    Person *firstPerson = [Person createEntity];
}

Any ideas on where I can begin troubleshooting?

@ski081
ski081 commented Jan 25, 2013

Never mind - I had another test case that was creating the model improperly and not tearing it back down. This was overriding the setUp method in the other test case, since the core data stack already existed at that point.

Closing this issue.

@ski081 ski081 closed this Jan 25, 2013
@fatuhoku
fatuhoku commented Jul 3, 2014

+1 This happened to me too, so thanks for leaving that note!

Ended up having to binary chop through the test cases to find the offending one. Now all is good.

@Glavin001 Glavin001 referenced this issue in Streamlyne/ios-app Jul 22, 2014
Closed

Cannot load Entities when setting up CoreData #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.