objective c - How to unit test my models now that I am using Core Data? -


I am developing an iPhone application using a domain model, and so far the persistence aspect of the app has been stopped. is. Core data really looks like a good solution because I already have a well-defined model but I'm having trouble with my current unit tests.

What I have now here:

  - (zero) test_full_name_returns_correct_string {patient * patient = [[patient allotment] init]; Patient.firstName = @ "Charlie"; Patient.lastName = @ "Chaplin"; STAssertTrue ([[Fully Feminine] is Extolstration: @ "Charlie Chaplin"], @ "Full Name Must Match"); }  

Once my patient object extends from NSManagedObject and uses @dynamic for the first name and last name properties, how can I do this?

Does anyone else do this with core data like this? Thank you.

You need to create a core data stack, either in each method or in Set up and then tear it using the NSInMemoryPersistentStore will keep things up and running in memory for your unit tests. Add a @ property (non-nominal, retaining) NSManagedObjectContext * moc in your testes sub-category. Then:

- (zero) set up {NSManagedObjectModel * mom = [NSManagedObjectModel mergedModeloftBundle: [NSArray arrayWithObject: bundleContainingXCDataModel]]; NSPersistentStoreCoordinator * psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: Mummy]; STAssertTrue ([psc addPersistentStoreWithType: NSInMemoryStoreType configuration: zero URL: zero option: zero error: NULL]? Yes: No, @ "should be able to add in-store store"); Self.moc = [[NSManedOvict.com Context Alloc] Init]; Self.moc.preistentStoreCoordinator = psc; [Mom Release]; [PSC release]; } - (zero) tearing {self.moc = zero; }

Find your test method:

  - (minus) test_full_name_returns_correct_string {patient patient = [NSEntityDescription insertNewObjectForEntityForName: @ "person" inManagedObjectContext: Itself .moc]; Patient.firstName = @ "Charlie"; Patient.lastName = @ "Chaplin"; STAssertTrue ([[patient's full name] isEqualToString: @ "Charlie Chaplin"] @ "full name should be matched"); }  

Assuming your unit has been name. The method, however, did not have a memory leak in its version; The patient should be -release 'non-core data version D ( insertNewObjectForEntityForName: managedObjectContext: is a autoreleased example)


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -