ios – 从命令行运行’Cedar’单元测试时出错

ios – 从命令行运行’Cedar’单元测试时出错,第1张

概述我正在使用雪松测试框架并尝试从命令行运行测试. 构建崩溃时出现此错误: Unresolved error Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x6c5c6c0 {reason=Failed to create file 我正在使用雪松测试框架并尝试从命令行运行测试.
构建崩溃时出现此错误:

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

其次我得到了同样的错误:“创建文件失败;代码= 2”

然后我查看了URL并看到了:

NSPersistentStoreCoordinator和NSManagedobjectModel的URL非常不同.但只有当我进行单元测试并且仅在修复第一个错误之后.

通常模型位于“/some/path/\u0026lt;DataModelfile\u0026gt;.app/\u0026lt;DataModel\u0026gt;.momd/
sqlite位于“some / path / documents /< sqlitefile> .sqlite中

因此,我使用以下代码在测试和运行中获取正确的URL:

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”文件夹.

如果这对您有用或如何更好地做出任何意见/建议,我们表示赞赏.

总结

以上是内存溢出为你收集整理的ios – 从命令行运行’Cedar’单元测试时出错全部内容,希望文章能够帮你解决ios – 从命令行运行’Cedar’单元测试时出错所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1007313.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存