I found that making use of compiler pre-process directives and bundling some test databases into your application (and using NSFileManager to copy the files across) makes testing with real data a breeze.
What I’ve done first is I have taken a copy of the iPhone database (Do a find . -name “ApplicationName” in the backup directory for your application OR if jailbroken do it in /var/mobile/Applications). Then you look for any sqlite files generated and now you can use this as a baseline test.
Next, create a folder in the xcode project (better organization!) called “QA” and then set up a target called “Test”, under the pre-processor directives add _TEST to this.
And finally the code
#if _TEST
NSLog(@"Application in Test Mode %@", [[NSBundle mainBundle] pathForResource:@"AppDB" ofType:@"sqlite" inDirectory:@""]);
NSLog(@"DEST: %@", [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"AppDB_Test.sqlite"]);
if ([[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"AppDB" ofType:@"sqlite" inDirectory:@""] toPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"AppDB_Test.sqlite"] error:nil]) {
NSLog(@"Copied DATABASE");
} else {
NSLog(@"Could not copy database");
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"AppDB_Test.sqlite"]];
#else
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"AppDB.sqlite"]];
#endif