【发布时间】:2016-02-20 03:33:44
【问题描述】:
我正在关注 Jon Reid 的 video。我一直遵循他的所有代码,直到出现错误。我不知道ResourceFetcher 是在哪里定义的,为什么这对我不起作用!代码如下:
在 ViewController 中:
-(void) fetchResources
{
NSString *string = [NSString stringWithFormat:@"%@weather.php?format=json", BaseURLString];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:string
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"%@",(NSDictionary *)responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"Error in retrieve data");
}
];
}
在 MockAFNetworkingGET 中:
@implementation MockAFNetworkingGET
-(AFHTTPRequestOperation *) GET : (NSString*) URLString
parameters:(NSDictionary *)parameters
success:(void (^)(AFHTTPRequestOperation * operation, id respondObject)) success
failure:(void (^)(AFHTTPRequestOperation * operation, NSError *error))failure
{
self.callCount += 1;
self.URLString = URLString;
self.parameters = parameters;
self.success = success;
self.failure = failure;
return self.fakeReturnValue;
}
@end
在 ResourceFetcherTests 中:
#import <XCTest/XCTest.h>
#import "MockAFNetworkingGET.h"
#import "ViewController.h"
@interface ResourceFetcherTests : XCTestCase
@end
@implementation ResourceFetcherTests
-(void) testFetchResources_shouldCallGet
{
id mockGet = [[MockAFNetworkingGET alloc]init];
ResourceFetcher *sut = [[ResourceFetcher alloc] initWithGETManager:mockGet];
//ResourceFetcher is not existing and giving me compiler error!!
}
@end
我已经复制并粘贴了教程中的所有代码。 ResourceFetcher 在这里不知道。我谷歌,但什么都没有出现!它是内置库还是我需要在某处定义或导入某个库?
这是幻灯片的链接:
【问题讨论】:
标签: ios objective-c mocking xctest