I used the answer above, Barry Work, but I had to make some changes to make it work with current Xcode5, iOS7 projects.
The property remains the same:
@interface SIDataTest : XCTestCase @property (nonatomic,retain) NSManagedObjectContext *moc; @end
The setting was, first of all, to change, so as not to release, and secondly, to provide the URL of the model.
- (void)setUp { [super setUp]; NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"SimpleInvoice" withExtension:@"momd"]; NSManagedObjectModel *mom = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom]; XCTAssertTrue([psc addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:NULL] ? YES : NO, @"Should be able to add in-memory store"); self.moc = [[NSManagedObjectContext alloc] init]; self.moc.persistentStoreCoordinator = psc; }
Here is a test case example:
- (void)testCreateNew { Invoice *newInvoice = [NSEntityDescription insertNewObjectForEntityForName:@"Invoice" inManagedObjectContext:self.moc]; newInvoice.dueDate = [NSDate date]; NSString* title = [[NSString alloc] initWithFormat:@"Invoice %@", @112]; newInvoice.title = title;
mikebz Jun 02 '14 at 5:56 on 2014-06-02 05:56
source share