• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using Core Data with OCUnit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using Core Data with OCUnit


  • Subject: Re: Using Core Data with OCUnit
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 10 Mar 2008 11:19:50 -0700

On Mar 10, 2008, at 2:36 AM, William Hunt wrote:

I'm having a bit of trouble getting my Core Data NSManagedObjectModel to load from within my unit tests. The code I'm using to load the model (and context) is in my application code, not in my unit test; but I do call it from my test class's setUp() method.

Your best bet is to implement a method in your application code to return the specific model itself, rather than the model that results from +[NSManagedObjectModel mergedModelFromBundles:]. In other words, something like this (typed in Mail):


- (NSManagedObjectModel *)managedObjectModel {
if (_managedObjectModel == nil) {
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"MyModel" ofType:@"mom"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath isDirectory:NO];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
}


    return _managedObjectModel;
}

Then you can just invoke this from both your application code and the - setUp method of your application code's unit tests and it should just work. It also ensures that you *only* get the configurations and entities defined in MyModel.mom.

  -- Chris

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Using Core Data with OCUnit
      • From: William Hunt <email@hidden>
References: 
 >Using Core Data with OCUnit (From: William Hunt <email@hidden>)

  • Prev by Date: Re: Glyph Generator & hiding glyphs -> _NSBlockNumberForIndex() errors
  • Next by Date: Re: Stupid question: how do you show an NSWindow?
  • Previous by thread: Using Core Data with OCUnit
  • Next by thread: Re: Using Core Data with OCUnit
  • Index(es):
    • Date
    • Thread