【发布时间】:2010-07-14 20:00:23
【问题描述】:
我正在尝试开始对使用 Core Data 的应用程序进行单元测试。在我的单元首次测试的 setUp 方法中,我可以获得数据模型的路径,但由于某种原因无法将其转换为 NSURL。
我的设置方法是:
- (void)setUp {
NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.testcompany.LogicTests"];
STAssertNotNil(bundle, @"Error finding bundle to create Core Data stack.");
NSString *path = [bundle pathForResource:@"DataModel" ofType:@"momd"];
STAssertNotNil(path, @"The path to the resource cannot be nil.");
NSURL *modelURL = [NSURL URLWithString:path];
STAssertNotNil(modelURL, @"The URL to the resource cannot be nil. (tried to use path:%@, modelURL is %@)", path, modelURL);
...
}
我得到的错误是:
/Users/neall/iPhone Apps/TestApp/UnitLogicTests.m:24:0 "((modelURL) != nil)" should be true. The URL to the resource cannot be nil. (tried to use path:/Users/neall/iPhone Apps/TestApp/build/Debug-iphonesimulator/LogicTests.octest/DataModel.momd, modelURL is (null))
我已经检查了文件系统并且目录/Users/neall/iPhone Apps/TestApp/build/Debug-iphonesimulator/LogicTests.octest/DataModel.momd 存在。
我在这里错过了什么?
谢谢!
【问题讨论】:
-
你能在某处上传一个示例项目吗?它应该以这种方式工作。
标签: iphone unit-testing core-data