【发布时间】:2014-08-20 09:18:14
【问题描述】:
我正在尝试使用 ocmock 学习单元测试。我发现很难从我正在单元测试的类中模拟另一个类的调用。
有人可以建议如何模拟调用 KeyChainUtils 类和 HttpRequest 类:
使用 OCMock 进行单元测试的代码:
@implementation UserProfileService {
+(BOOL) isValidUser
{
NSString* userId = [KeyChainUtil loadValueForKey:USER_ID]; //mock this call
bool isValidUser = NO;
if(userId && userId.length > 0){
NSDictionary* response = [HTTPDataService getJSONForURL:@"http://xtest.com/checkuserid" forRequestData:@{@"userid": userId}];
if(response && response[@"valid"]){
isValidUser = [response[@"valid"] boolValue];
}else{
NSLog(@"error in connecting to server. response => %@", response);
}
}
return isValidUser;
}
}
【问题讨论】:
标签: objective-c ocmock ocmockito