Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK. I got it working ... </p> <ol> <li><p>Create LogicTests as described here (section setting up Logic Testing): <a href="http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html">http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html</a></p></li> <li><p>Manually add the CoreData.framework to the newly created Target for the Logic Tests: Drag it from the application target to the logic test target (folder "link binary with libraries).</p></li> <li><p>Right-click on your *.xcdatamodeld and select Get Info -> Targets. Select the Logic Tests target (for some strange reason the actual application target was not selected in my case ... but that works)</p></li> <li><p>In your unit test class (you created in step 1: LogicTests.m) add the following method:</p> <pre><code>- (void) setUp { NSArray *bundles = [NSArray arrayWithObject:[NSBundle bundleForClass:[self class]]]; NSManagedObjectModel *mom = [NSManagedObjectModel mergedModelFromBundles:bundles]; STAssertNotNil(mom, @"ManangedObjectModel ist nil"); NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom]; STAssertTrue([psc addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:NULL] ? YES : NO, @"Should be able to add in-memory store"); self.context = [[NSManagedObjectContext alloc] init]; self.context.persistentStoreCoordinator = psc; [mom release]; [psc release]; } </code></pre></li> </ol> <hr> <p>Now you have a Logic Test with Core Data support set up. The logic testing is done in isolation (without simulator) by building the LogicTests target. For this a temporary in-memory database is created. In your test methods you can now do something like:</p> <pre><code>- (void) testStuff { NSManagedObject *managedObj = [NSEntityDescription insertNewObjectForEntityForName:@"Account" inManagedObjectContext:self.context]; [managedObj setValue:[NSNumber numberWithInt:90000] forKey:@"id"]; NSError *error = nil; if (![self.context save:&amp;error]) { STFail(@"Fehler beim Speichern: %@, %@", error, [error userInfo]); } } </code></pre> <p>Hope this helps.... Have fun!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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