非常に多くの「if 条件」があり、条件が配列数をチェックしている複雑なメソッドに対して、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;
}
これらの種類のメソッドの単体テストを作成する方法は?