首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DIfficulty模拟核心数据对象

DIfficulty模拟核心数据对象
EN

Stack Overflow用户
提问于 2012-09-26 01:59:04
回答 1查看 760关注 0票数 2

我正在对一个使用核心数据的模型文件运行单元测试。测试目标构建成功,但我看到以下错误:

错误:(FolderDALTests)失败:+entityForName:在此模型中找不到名为'Folder‘的实体。

错误: testThatFindByExchageAccountReturnsFolders (FolderDALTests)失败:+entityForName:在此模型中找不到名为'ExchangeAccount‘的实体。

然而,我觉得这个问题是由"setup“方法引起的,在”setup“方法中,NSManagedObjectModel不是使用合并包中找到的所有模型来创建的。

代码语言:javascript
复制
-(void)testThatDistinguishedFolderTypeForTheAccountExists
 {
   Folder *inbox = [NSEntityDescription insertNewObjectForEntityForName:@"Folder" 
   inManagedObjectContext:self.context];
   inbox.distinguishedFolderType = @"inbox";
   ExchangeAccount *account = [NSEntityDescription insertNewObjectForEntityForName:@"ExchangeAccount" inManagedObjectContext:self.context];
   id<FolderProtocol> folder = [FolderDAL findWithAccount:account DistinguishedFolderType:@"inbox" withManagedContext:self.context];

STAssertTrue([folder.folderDistinguishedFolderType isEqualToString:@"inbox"], @"Unable to find the folder with the given distinguished type");

}

另一种方法是:

代码语言:javascript
复制
- (void)testThatFindByExchageAccountReturnsFolders
  {
      ExchangeAccount *account = [NSEntityDescription          insertNewObjectForEntityForName:@"ExchangeAccount" inManagedObjectContext:self.context];

     Folder *inbox = [NSEntityDescription insertNewObjectForEntityForName:@"Folder"     inManagedObjectContext:self.context];
     inbox.displayName = @"Inbox";
     inbox.exchangeAccount = account;

     Folder *calendars = [NSEntityDescription insertNewObjectForEntityForName:@"Folder" inManagedObjectContext:self.context];
     calendars.displayName = @"Calendars";
     calendars.exchangeAccount = account;

     NSArray *folders = [FolderDAL findByExchangeAccount:account withContext:self.context];

     STAssertTrue([folders count] > 0, @"No folders were returned");
  }

设置方法为:

代码语言:javascript
复制
- (void)setUp
{
  [super setUp];

  NSManagedObjectModel *objectModel = [NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:[NSBundle mainBundle]]];
  NSPersistentStoreCoordinator *storeCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:objectModel];
  STAssertTrue([storeCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:NULL] ? YES : NO, @"Should be able to add in-memory store");
  self.context = [[NSManagedObjectContext alloc] init];
  self.context.persistentStoreCoordinator = storeCoordinator;

}

这里,"Folder“和"ExchangeAccount”是核心数据实体。和它们对应的DAL(数据访问层)文件有它们的一些业务逻辑

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-12 14:05:21

我忘了将单元测试作为目标添加到模式中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12588544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档