Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:08:08+00:00 2026-06-02T08:08:08+00:00

I am trying to use CoreData in a SenTestCase. The problem is the NSManagedObjectModel

  • 0

I am trying to use CoreData in a SenTestCase. The problem is the NSManagedObjectModel which is not found. I have tried to initialize it with a URL by searching for the mom file in the application bundle but I could not find it. That is why I switched to:

NSManagedObjectModel *objectModel = [NSManagedObjectModel mergedModelFromBundles:nil];

This does work properly but only in the main application. If I try to run it in the SenTestCase the returned objectModel does not have any entities:

(gdb) po objectModel
(<NSManagedObjectModel: 0xab72480>) isEditable 0, entities {
}, fetch request templates {
}

I have to admit that I do not know what kind of setup is needed to generate the mom file. I have added the .xcdatamodeld file to the list of compiled sources in the application’s target and the test target.

The following code is working properly in the applications ViewController viewDidLoad method but is not working in a test case of a SenTestCase class:

- (void)testCoreData {
    NSManagedObjectModel *objectModel = [NSManagedObjectModel mergedModelFromBundles:nil];


    NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init];


    NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: objectModel];
    [context setPersistentStoreCoordinator: coordinator];

    NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    url = [url URLByAppendingPathComponent:@"TestDatabase"];

    NSLog(@"Path: %@", url);

    NSError *error;

    NSPersistentStore *newStore = [coordinator addPersistentStoreWithType:NSSQLiteStoreType
                                                        configuration:nil
                                                                  URL:url
                                                              options:nil
                                                                error:&error];

    if (newStore == nil) {
        NSLog(@"Store Configuration Failure\n%@",
              ([error localizedDescription] != nil) ?
              [error localizedDescription] : @"Unknown Error");
    }

    TaskSet *taskSet = [NSEntityDescription insertNewObjectForEntityForName:@"TaskSet" 
                                                 inManagedObjectContext:context];
    taskSet.taskSetId = @"1234";

    NSLog(@"TaskSet: %@", taskSet);
    NSError *saveError;
    if ([context save:&saveError]) {
        NSLog(@"Store Saved successfully");
    } else {
        NSLog(@"Store not saved! Error: %@", saveError);
    }
}

Error:

Catchpoint 3 (exception thrown).Unknown.m:0: error: -[ControllerTest testCoreData] : +entityForName: could not locate an entity named 'TaskSet' in this model.

What is the difference between running in a SenTestCase and running in viewDidLoad ? What do I need to do to compile the core data model into a test case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:08:10+00:00Added an answer on June 2, 2026 at 8:08 am

    This question has been answered before: Unit Test can't find Core Data model file

    The credit goes to Luther Baker for pointing out that SenTestCases are not using the main Bundle. If you want to write data to a file you have to create the bundle with an identifier as described in his answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use CoreData to populate a UITableView. I have been using
I am trying to use validatevalue:forkey: method to validate a coredata property. I have
Hi I'm trying use a datepicker on a field I have. I'm trying to
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I'm trying to implement search code in my CoreData-based iPhone app. I'm not sure
I have this statement that im trying to figure out how to use in
I have a CoreData app with the MainView the UITableViewController which houses all of
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.