我正在使用雪松测试框架并尝试从命令行运行测试.
构建崩溃时出现此错误:
构建崩溃时出现此错误:
Unresolved error Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x6c5c6c0 {reason=Failed to create file; code = 2},{ reason = "Failed to create file; code = 2"; }
测试从xcode运行没有任何问题,我只是无法让他们从命令行工作.
有任何想法吗?
谢谢
解决方法
我在单元测试和核心数据方面遇到了同样的问题:
首先我遇到了“找不到商店模特”.我用这个帖子解决了这个问题:Error running ‘Cedar’ unit tests from command line
然后我查看了URL并看到了:
NSPersistentStoreCoordinator和NSManagedObjectModel的URL非常不同.但只有当我进行单元测试并且仅在修复第一个错误之后.
通常模型位于“/some/path/\u0026lt;DataModelFile\u0026gt;.app/\u0026lt;DataModel\u0026gt;.momd/
sqlite位于“some / path / Documents /< sqliteFile> .sqlite中
NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSURL *modelURL = [bundle URLForResource:@"WinNav" withExtension:@"momd"]; basePath = @""; NSArray *arr = [modelURL pathComponents]; for (int i=0; i<[arr count]-2; i++) { basePath = [basePath stringByAppendingString:[arr objectAtIndex:i]]; if (i > 0) basePath = [basePath stringByAppendingString:@"/"]; } NSLog(@"modelURL: %@",modelURL); NSURL *storeUrl = [NSURL fileURLWithPath:[basePath stringByAppendingString:@"/Documents/Locations.sqlite"]];
如果我没记错,那么我必须创建存储sqlite文件的“Documents”文件夹.
如果这对您有用或如何更好地做出任何意见/建议,我们表示赞赏.