我想测试一种发出 URL 请求的方法。在NSURLConnectionDelegate
方法中收到响应时,我保存响应。我真正想测试的逻辑是响应是否被保存。
如何测试NSURLConnectionDelegate
方法?
我想测试的方法:
- (void) getProfilePictureURL :(NSString *)fbId
{
//to get picture URL
NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", fbId];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (!connection)
{
NSLog(@"error while starting the connection");
}
}
// NSURLConnectionDelegate method
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// Save response in user defaults
}