【发布时间】:2015-12-24 20:21:37
【问题描述】:
在 XCTest 类中,我得到这样的托管对象上下文:
//setup Core Data Stack
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"FabApp" withExtension:@"momd"];
NSManagedObjectModel *mom = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
NSError *error = nil;
XCTAssertTrue([psc addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:&error] ? YES : NO, @"Should be able to add in-memory store");
self.moc = [[NSManagedObjectContext alloc] init];
self.moc.persistentStoreCoordinator = psc;
ManagedObejctContex 已成功创建,但是当我尝试获取某些实体时,它没有找到任何实体。当我在应用程序中使用这些实体时,我 100% 确定这些实体存在于 Core Data 中
- (void) testAllInputIsSavedInCoreData{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Employ"
inManagedObjectContext:_moc];
[fetchRequest setEntity:entity];
NSError *error = nil;
NSArray *results = [_moc executeFetchRequest:fetchRequest error:&error];
XCTAssertEqual([[_lines objectAtIndex:0] count], [results count],@"Missmatch in saved data read %lu but saved %lu",(unsigned long)[[_lines objectAtIndex:0] count], (unsigned long)[results count]);
}
这怎么可能,我错过了什么吗?
【问题讨论】:
-
您是否尝试过在模拟器中删除您的项目应用并再次运行它?
-
是的,现在。没用!
标签: ios objective-c core-data ios9 xctest