刚刚在AFNetworking / Tests上安装了pod 安装AFNetworking(2.0.1) 安装Expecta(0.2.3) 安装OCMock(2.1.1) 生成Pods项目 集成客户端项目
测试运行,但我在期望返回错误块的测试中出现错误...
testThatCancellationOfRequestOperationInvokesFailureCompletionBlock
testThat500StatusCodeInvokesFailureCompletionBlockWithErrorOnFailure
testThatCancellationOfRequestOperationSetsError
调试显示错误块为零。
测试正在向https://httpbin.org/status/404(第一次测试)或http://httpbin.org/status/500(第二次测试)发送请求。 httpbin按预期工作(对于第一种情况,http结果代码为404,对于第二种情况,http结果为500,如预期的那样。
虽然响应包含错误代码(在一个测试用例中为404,在另一个测试用例中为500),但AFNetworking代码不会带有错误对象::
- (void)testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure {
__block NSError *blockError = nil;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
// AFHTTPOperation currently does not have a default response serializer
[operation setResponseSerializer:[AFHTTPResponseSerializer serializer]];
[operation setCompletionBlockWithSuccess:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) {
blockError = error;
}];
[operation start];
expect([operation isFinished]).will.beTruthy();
expect(blockError).willNot.beNil();
}
在expect(blockError).willNot.beNil();
时,blockError为nil。
错误日志是:
Test Suite 'All tests' started at 2013-10-21 18:11:28 +0000
Test Suite 'iOS Tests.xctest' started at 2013-10-21 18:11:28 +0000
Test Suite 'AFHTTPRequestOperationTests' started at 2013-10-21 18:11:28 +0000
Test Case '-[AFHTTPRequestOperationTests testThatOperationPostsDidFinishNotificationWhenFinished]' started.
Test Case '-[AFHTTPRequestOperationTests testThatOperationPostsDidFinishNotificationWhenFinished]' passed (0.001 seconds).
Test Case '-[AFHTTPRequestOperationTests testThatPausedOperationCanBeResumed]' started.
Test Case '-[AFHTTPRequestOperationTests testThatPausedOperationCanBeResumed]' passed (0.000 seconds).
Test Case '-[AFHTTPRequestOperationTests testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure]' started.
2013-10-21 14:11:28.831 xctest[4261:303] (null)
2013-10-21 14:11:33.837 xctest[4261:303] /Users/onetokadmin/Downloads/AFNetworking-master/Tests/Tests/AFHTTPRequestOperationTests.m:69 expected: not nil/null, got: nil/null
/Users/onetokadmin/Downloads/AFNetworking-master/Tests/Tests/AFHTTPRequestOperationTests.m:69: error: -[AFHTTPRequestOperationTests testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure] : expected: not nil/null, got: nil/null
Test Case '-[AFHTTPRequestOperationTests testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure]' failed (5.362 seconds).
将继续工作,但认为这可能是新版本的疏忽。