gpt4 book ai didi

ios - 从命令行运行 'Cedar' 单元测试时出错

转载 作者:可可西里 更新时间:2023-11-01 05:57:04 28 4
gpt4 key购买 nike

我正在使用 cedar 测试框架并尝试从命令行运行测试。构建因以下错误而崩溃:

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/ .app/ .momd/
sqlite 在 "some/path/Documents/ .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' 单元测试时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12363319/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com