我有方法我想进行单元测试:
- (void)fetchInfo {
[AMKAccountService getInfo]
.then(^(AMKInfoResponse *response) {
if (response.accounts.count > 0) {
_viewModel = [[AMKInfoViewModel alloc] initWithInfoResponse:response];
[self.view setAsOfDate:_viewModel.asOfDate];
} else {
[self.view showError:[AMKStrings feedbackForCode:@"testError"]];
}
}).catch(^(NSError *error) {
DLog(@"Error getting info: %@", error);
[self.view showError:[AMKStrings feedbackForCode:@"testError"]];
});
}
在此方法中,'getInfo'方法进行服务调用并返回PMKPromise对象类型的响应。
我的问题是如何模拟getInfo方法并使'then'块调用一个单元测试,并调用'catch'块进行其他单元测试。
[更新] 这是getInfo方法:
+ (PMKPromise *)getInfo {
AMKServicesClient *client = [AMKServicesClient sharedInstance];
return [client GET:@"/amk-web-services/rest/info" parameters:nil].thenInBackground(^(NSDictionary *responseDictionary) {
return [[AMKInfoResponse alloc] initWithResponse:responseDictionary];
});
}