如何使用 OCMock 为具有如此多“if 条件”的复杂方法编写单元测试,并且 contions 正在检查数组计数。这是我的示例方法:
- (BOOL)someMethod
{
BOOL bUploadingLocation = false;
CLLocation *newLocation = nil;
if([locationCallbacks count] > 0)
{
for(CLLocation* receivedlocation in locationCallbacks) {
//Print
}
newLocation = [locationCallbacks objectAtIndex:[locationCallbacks count] - 1];
}
else
{
return bUploadingLocation;
}
BOOL initialLocation = false;
CLLocation *lastKnownLocation = [[ASAppProfileService sharedInstance] getStoredLastKnownLocation];
if(lastKnownLocation == nil)
{
initialLocation = true;
}
BOOL checkedInstatusChange = false;
if([[CRMgr getSharedInstance] isCREnabled])
{
checkedInstatusChange = [[CRMgr getSharedInstance] orchestrateCROperationsWithLocation:newLocation];
}
BOOL lastGoodUploadIsWithinThresold = [MELocationUtils isLastAccurateUploadWithinThresold];
if(initialLocation || checkedInstatusChange || !lastGoodUploadIsWithinThresold)
{
BOOL bCanUpload = [[ASAppProfileService sharedInstance] canUploadData];
if(bCanUpload)
{
[[MEProtocolHelper sharedDataUploadManager] uploadLocationInformationPayload:newLocation];
bUploadingLocation = true;
}
else
{
//Print something
}
}
return bUploadingLocation;
}
如何为这些方法编写单元测试?