Im новое для модульного тестирования и OCMock, поэтому это может быть очевидный ответ, просто не нашел ответа на google. Я пытаюсь проверить метод объекта модели. метод имеет следующий код:mocking a class - iOS
//takes a filepath and a pk, sets the filepath to the
BoxAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSNumber *ifExistIndexInJson = [BoxJsonDataHelper pkExistInCurrentJson:[[[self.downloadQueue objectAtIndex:0] objectForKey:@"pk"] integerValue]];
if (ifExistIndexInJson)
{
[[[self.downloadQueue objectAtIndex:0] objectForKey:@"fields"] setObject:path forKey:@"content"];
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtPath:[[[delegate.currentJsonData objectAtIndex:[ifExistIndexInJson integerValue]] objectForKey:@"fields"] objectForKey:@"content"] error:&error];
[delegate.currentJsonData removeObjectAtIndex:[ifExistIndexInJson integerValue]];
[delegate.currentJsonData addObject:[self.downloadQueue objectAtIndex:0]];
[self.downloadQueue removeObjectAtIndex:0];
if ([self.downloadQueue count] > 0)
{
[BoxServerRequestsObject downloadFileForPK:[[[self.downloadQueue objectAtIndex:0] objectForKey:@"pk"] integerValue]sender:self];
}
else
{
//end the progress or whatever
}
}
else
{
[[[self.downloadQueue objectAtIndex:0] objectForKey:@"fields"] setObject:path forKey:@"content"];
[delegate.currentJsonData addObject:[self.downloadQueue objectAtIndex:0]];
[self.downloadQueue removeObjectAtIndex:0];
if ([self.downloadQueue count] > 0)
{
[BoxServerRequestsObject downloadFileForPK:[[[self.downloadQueue objectAtIndex:0] objectForKey:@"pk"] integerValue]sender:self];
}
else
{
//end the progress or whatever
}
}
мне нужна помощь с парой вещей:
, когда я звоню [BoxJsonDataHelper pkExistInCurrentJson: ...]. BoxJsonDataHelper на самом деле сам, только это метод класса, а не экземпляр, поэтому я называю его по имени. Как я могу подделать результаты возвращаемого значения, чтобы не было никакой зависимости?
Как подделать файл по пути для удаления программы? чем я могу проверить, что он был удален?
Как мне высмеять BoxServerRequestObject, чтобы заставить метод вызывать макетный объект вместо реального? и чем, как я могу проверить, если она была вызвана (также метод класса)
Мои знания в модульном тестировании ограничено, и я только начал с OCMock и прочитать некоторые примеры, так что я был бы признателен за исчерпывающие ответы:)
Я nit- но они продолжают насмехаться, пока не назовете -stopMocking или макет dealloc'd. Очень важно, чтобы вы вызывали stopMocking, как только закончите тест, если вы издеваетесь над методами классов инфраструктуры, например NSURLConnection. – ImHuntingWabbits