Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In order to instantiate an NSManagedObject, you need an entity. Thus what you first tried — either passing <code>nil</code> for the entity or using bare <code>-init</code> (which isn't supported on NSManagedObject) — didn't work. You're doing the right thing by using <code>-[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:]</code> to create the object, you just need to:</p> <ol> <li>Make sure that the entity TimeEntry exists in your data model.</li> <li>Make sure that the <em>entity</em> TimeEntry is associated with the <em>class</em> TimeEntry in your data model.</li> <li>Make sure that your data model is actually loaded by your tests.</li> </ol> <p>Note that unless you specifically want to test save/delete validation, you generally won't need to add a persistent store to your coordinator. (And if you're using an SQLite persistent store in your app, I'd strongly suggest using one in your tests too; the different persistent store types have different performance characteristics and supported queries.)</p> <p>For ensuring your data model is loaded, you'll find it much more fruitful I think to actually specify the URL to load it from, instead of just hoping that you've put it in the right place and that <code>-mergedModelFromBundles:</code> will do the right thing. I'd make it a member of your unit test bundle target, so it's compiled into your unit test bundle's Resources. That way you can just use an appropriate NSBundle method to get the path or URL to it.</p> <p>Finally, you're going to want to put the set-up of your Core Data persistence stack — the model, persistent store coordinator, and a scratch context — in a <code>-setUp</code> method in your test case. Or in a <code>-setUp</code> method of a test case base class, if you want to create more than one test case class. (The same goes for tear-down of the persistence stack and <code>-tearDown</code> methods, of course.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload