objective c - Logic Test vs Application Test - Conflicting Results -
i have 2 test targets in project, logic test (modellogictests) , application test (myapptests). have 1 class use in both test models built json objects.
the test case follows:
// modellogictests.m @interface mymodellogictests : xctestcase @property nsmanagedobjectcontext *context; @property nsmanagedobjectmodel *model; @property nspersistentstorecoordinator *store; @property nsbundle *bundle; @end @implementation mymodellogictests - (void)setup { [super setup]; nsbundle *bundle = [nsbundle bundleforclass:[self class]]; nsarray *bundles = @[ bundle ]; self.bundle = bundle; self.model = [nsmanagedobjectmodel mergedmodelfrombundles:bundles]; xctassertnotnil( self.model, @"managed object model \'nil.\'" ); self.store = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:self.model]; xctasserttrue( self.store, @"persistent store coordinator did not initialize properly." ); nserror *storeerror = 0; nspersistentstore *tempstore = [self.store addpersistentstorewithtype:nsinmemorystoretype configuration:nil url:nil options:nil error:&storeerror]; xctassertnil( storeerror, @"error: %@", storeerror.debugdescription ); xctassertnotnil( tempstore, @"\'tempstore\' should not \'nil.'" ); self.context = [[nsmanagedobjectcontext alloc] init]; self.context.persistentstorecoordinator = self.store; xctassert( self.context, @"nsmanagedobjectcontext did not initlaize." ); xctassert( self.context.persistentstorecoordinator, @"context's persistent store did not stored." ); } - (void)testbuildsimplemodel { nsurl *path = [self.bundle urlforresource:@"simplemodel" withextension:@"json"]; xctasserttrue( [path iskindofclass:[nsurl class]], @"\'path\' instance of \'%@.\'", [path class] ); nsdata *jsondata = [[nsdata alloc] initwithcontentsofurl:path]; xctasserttrue( [jsondata iskindofclass:[nsdata class]], @"" ); nserror *jsonerror = 0; nsdictionary *json_dict = [nsjsonserialization jsonobjectwithdata:jsondata options:0 error:&jsonerror]; xctassertnil( jsonerror, @"json error: %@", jsonerror.description ); xctasserttrue( [json_dict iskindofclass:[nsdictionary class]], @"" ); xctassertequalwithaccuracy(json_dict.count, (nsuinteger)4, 0, @"" ); myspot *spot = [myspot buildmyspotfromjson:json_dict context:self.context]; xctassertnotnil( spot, @"" ); // problem test here when running application test xctasserttrue( [spot iskindofclass:[myspot class]], @"is instance of \'%@.\'", nsstringfromclass([spot class]) ); nserror *saveerror = 0; xctasserttrue( [self.context save:&saveerror], @"save error: %@", saveerror.debugdescription ); xctassertequalobjects( spot.name, @"montreal", @"" ); xctassertequalwithaccuracy(spot.latitude.floatvalue, (cgfloat)45.5, 0.0, @"" ); xctassertequalwithaccuracy(spot.longitude.floatvalue, (cgfloat)-73.566667, 0, @"" ); xctassertequalwithaccuracy( spot.status.integervalue, (myspotstatus)myspotstatusopen, 0, @"should \'open.\'" ); }
the issue this, running logic, tests pass expected. under application test, following test fails:
xctasserttrue( [spot iskindofclass:[myspot class]], @"is instance of \'%@.\'", nsstringfromclass([spot class]) );
and output is:
-[mymodellogictests testbuildsimplemodel] : (([spot iskindofclass:[myspot class]]) true) failed - instance of 'myspot.'
i have double checked resource files, model, , source files, have been added necessary targets.
why failed test (as above), when spot instance of myspot?
update:
as suggested, added:
nslog( @"instance class: %p, class: %p", [spot class] , [myspot class] ) // logic test output instance class: 0x5a178ac, class: 0x5a178ac // app test output instance class: 0x6fa24, class: 0x9ead2cc
so updated question is, why difference between application tests , logic test?
Comments
Post a Comment