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 8183625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:13:14+00:00 2026-06-07T01:13:14+00:00

Is there a simple way out there to create NSManagedObjects for testing reasons without

  • 0

Is there a simple way out there to create NSManagedObjects for testing reasons without to use the managed object context created for the release Application?

I’m now into Core Data coding for a couple of weeks but still having some issues in the details … why can’t I just alloc and init objects for testing? Do I really have to handle with a second persistant store / managed object context (and which one)?

I have to test some methods written in my NSManagedObject subclasses …

  • 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-07T01:13:16+00:00Added an answer on June 7, 2026 at 1:13 am

    Trust me, you do NOT want to test core data objects without using a MOC. You have to do unsound things at best.

    However, if you don’t want to use your actual database, use an in memory store. It’s very simple to set up. In fact, it’s what I use for a lot of my own unit testing.

    I caution you, though. There are a number of things that do not behave the same with SQL stores and in-memory stores. The most common problem will be with predicates. Read the docs to make sure your predicates are right.

    I will say that during testing, you can use the in-memory MOC, but you should have a configuration that runs ALL you tests on the actual database itself to make sure it al works. For speed, maybe you use the in-memory database for normal use, and use the actual one for scheduled continuous-integration testing.

    As an example, you can do something like this to create your in-memory MOC…

    - (NSManagedObjectContext*)managedObjectContextWithConcurrencyType:(NSManagedObjectContextConcurrencyType)concurrencyType {
        NSManagedObjectModel *mom = [NSManagedObjectModel mergedModelFromBundles:nil];
        STAssertNotNil(mom, @"Can not create MOM from main bundle");
    
        NSPersistentStoreCoordinator *psc = [[MyPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
        STAssertNotNil(psc, @"Can not create persistent store coordinator");
        NSPersistentStore *store = [psc addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:0];
        STAssertNotNil(store, @"Can not create In-Memory persistent store");
    
        MyManagedObjectContext *moc = [[MyManagedObjectContext alloc] initWithConcurrencyType:concurrencyType];
        moc.persistentStoreCoordinator = psc;
    
        return moc;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to clear out the responseText of an XHR object without
Is there some simple way to send out a ping-style message to a remote
I am trying to figure out if there is a simple way to display
Question : Is there a simple way to print out an array in Ruby
It's simple - is there a way to use this lib to call stored
I'm trying to figure out if there is some way to create a dynamic
Is there any simple way to create a column in MS SQL that will
Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon
Is there a simple way to serialize a single-level structure as a string for
Is there a simple way, possibly with open-source command line tools in Linux, to

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.