我在启动和运行我的测试套件时遇到了一些麻烦。基本上我向我的应用程序添加了一个新目标,如下所示: 单元测试应用程序
当我想针对我的 DA 类和 sqlite-database 进行测试时,我使用以下片段来复制数据库:
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:DATABASE_Path];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:DATABASE_Path];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
但看起来,NSBundle 并没有按预期返回数据库的路径。
有一个简单的解决方法吗?在过去的几个小时里我没能修好它——所以我的下一个镜头就是你们。
任何帮助或建议都非常感谢!
非常感谢!
汤姆