Skip to content

Instantly share code, notes, and snippets.

@nvie
Created March 29, 2011 19:18
Show Gist options
  • Save nvie/893044 to your computer and use it in GitHub Desktop.
Save nvie/893044 to your computer and use it in GitHub Desktop.
Using an SQLite in-memory store for your tests
#import <SenTestingKit/SenTestingKit.h>
@implementation TestFoo
- (void)setUp
{
[super setUp];
// We use a in memory store instead of the real SQLite
// Store the model, coord and store in instance variables
model = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
coord = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
store = [coord addPersistentStoreWithType:NSInMemoryStoreType
configuration:nil
URL:nil
options:nil
error:NULL];
moc = [[NSManagedObjectContext alloc] init];
[moc setPersistentStoreCoordinator: coord];
// TODO: Fill the moc with fixture data here
NSError *error;
[moc save:&error];
}
- (void)tearDown
{
[moc release];
[coord release];
[store release];
[super tearDown];
}
// TODO: Your test methods here
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment