Created
March 29, 2011 19:18
-
-
Save nvie/893044 to your computer and use it in GitHub Desktop.
Using an SQLite in-memory store for your tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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