So...I'm trying to get unit tests set up in my iPhone App but I'm having some issues. I'm trying to test my model classes but they inherit directly from NSManagedObject. I'm sure this is a problem but I don't know how to get around it.
Everything is building and running as expected but I get this error when calling any method on the class I'm testing:
Unknown.m:0:0 unrecognized selector sent to instance 0xc2b120
If I follow this structure to create my object in my tests I end up with another error entirely but it still doesn't help me.
If I instantiate my model like this:
entry = [[TimeEntry alloc]
initWithEntity:nil
insertIntoManagedObjectContext:nil];
Then I end up with this error at runtime:
An NSManagedObject of class 'TimeEntry' must have a valid NSEntityDescription.
If I try it like this:
entry = [[TimeEntry alloc] init];
Then I end up with this error:
unrecognized selector sent to instance 0xc2b120
And if I follow the pattern laid out here:
model = [[NSManagedObjectModel mergedModelFromBundles: nil] retain];
NSLog(@"model: %@", model);
coord = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: model];
store = [coord addPersistentStoreWithType: NSInMemoryStoreType
configuration: nil
URL: nil
options: nil
error: NULL];
ctx = [[NSManagedObjectContext alloc] init];
[ctx setPersistentStoreCoordinator: coord];
entry = (TimeEntry *)[NSEntityDescription insertNewObjectForEntityForName:@"TimeEntry" inManagedObjectContext:ctx];
Then I get this error:
could not locate an entity named 'TimeEntry' in this model.
Basically my question is this: how can I test a class that inherits from NSManagedObject?