I'm attempting to write an integration test using the OCUnit/SenTest Framework which I feel relatively comfortable with. The test is regarding the loading of an NSPersistentDocument-subclass which relies on a CoreData Managed Object Model which is being successfully imported.
What is the best method to go about this? I've been trying all day and it's been one problem after another. Doing this (trimmed for relevence):
NSManagedObjectContext *moc = [NSManagedObjectContext new];
[moc setPersistentStoreCoordinator:coordinator];
MyDocument *mdoc = [MyDocument new];
[mdoc setManagedObjectContext:moc];
STAssertTrue([mdoc readFromURL:docUrl ofType:@"dfb" error:&error], @"File not loaded: %@", [error localizedDescription]);
results in no error, but the document's Managed Ob开发者_开发技巧ject Context is empty - that is, [[mdoc.managedObjectContext registeredObjects] count]
is zero.
Running the main application (not under unit tests) works as expected. The file at docUrl loads and the interface populates correctly.
What am I missing?
Your code seems to be mixing two initialization styles. NSPersistentDocument
sets up its Core Data stack automatically, in -init
.
Try this instead:
MyDocument *mdoc = [[MyDocument alloc] init];
STAssertTrue([mdoc readFromURL:docUrl ofType:@"dfb" error:&error],
@"File not loaded: %@", [error localizedDescription]);
精彩评论