如何使用OCMock編寫一個複雜的方法,它有很多「如果條件」和contions正在檢查數組計數的單元測試。這裏是我的示例方法:使用OCMock的複雜方法的單元測試
- (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;
}
如何爲這些類型的方法編寫單元測試?