Unit testing difficulties #354

ketzusaka opened this Issue Dec 29, 2012 · 4 comments


None yet

2 participants


I've been working on getting unit testing working for a while now with MagicalRecord. The main issue I've been having is that the main bundle isn't where the resources are loaded within the unit test.

I learned that from this:

My bundle path inside my unit spec was: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/Developer/usr/bin

I looped through that directory and there were only two items: otest and ScriptAgent

I had thought that MagicalRecord provided a way around this with:

  • (NSManagedObjectModel *) MR_newModelNamed:(NSString *) modelName inBundleNamed:(NSString *) bundleName;

But on the contrary, it looked within the main bundle for a sub-bundle. I suggest adding the following method to the category:

  • (NSManagedObjectModel *) MR_newModelNamed:(NSString *) modelName inBundleIdentifiedBy:(NSString *) bundleIdentifier {
    NSString *path = [[NSBundle bundleWithIdentifier:bundleIdentifier] pathForResource:[modelName stringByDeletingPathExtension]
    ofType:[modelName pathExtension]];
    NSURL *momURL = [NSURL fileURLWithPath:path];

    return [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];

Let me know if you'd like me to do that and do a pull request on it, or if you have any other thoughts.


Magical Panda Software member

That method that he is referencing no longer exists within MagicalRecord.


Guess it was renamed to setDefaultModelFromClass

That's definitely easier then what I was doing with it. Thanks.

Magical Panda Software member

If you look under the "Supporting Xcode’s Unit Test Support" section his code snippet is:

  • (void)setUp; { [MagicalRecord setDefaultModelFromClass:[self class]]; [MagicalRecord setupCoreDataStackWithInMemoryStore]; }

Further down, where he gives a more complete example, with the following setUp:

  • (void)setUp; { [MagicalRecord setDefaultModelWithClass:[self class]]; [MagicalRecord setupCoreDataStackWithInMemoryStore]; }

Notice in the first it's setDefaultModelFromClass. That's the one I caught first =)

@ketzusaka ketzusaka closed this Dec 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment