I would like to get an advice regarding how to test the same code with different input data.
I would like to test that method operationSucceeded
will be invoked for all successful status codes. Here is how I can test (with Kiwi) single status code (i.e. 200):
it(@"should call operationSucceeded", ^{
MKNetworkOperation *op =[[MKNetworkOperation alloc] initWithURLString:@"http://example.com/api" params:nil httpMethod:@"GET"];
[op stub:@selector(notifyCache)];
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:nil
statusCode:200
HTTPVersion:nil
headerFields:nil];
[op stub:@selector(response) andReturn:response];
[[op should] receive:@selector(operationSucceeded)];
[op connectionDidFinishLoading:[NSURLConnection nullMock]];
});
For now I do next:
it(@"should call operationSucceeded", ^{
NSArray *successCodes = @[@200, @201, @202, @203, @204, @205, @206];
for (NSNumber *statusCode in successCodes) {
MKNetworkOperation *op =[[MKNetworkOperation alloc] initWithURLString:@"http://example.com/api" params:nil httpMethod:@"GET"];
[op stub:@selector(notifyCache)];
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:nil
statusCode:[statusCode intValue]
HTTPVersion:nil
headerFields:nil];
[op stub:@selector(response) andReturn:response];
[[op should] receive:@selector(operationSucceeded)];
[op connectionDidFinishLoading:[NSURLConnection nullMock]];
}
});
But the main problem here is that if my test fail for one of status codes it will say something like: "'Operation, should call operationSucceeded' [FAILED], expected subject to receive -operationSucceeded exactly 1 time, but received it 0 times" which is not very useful.
You can find full source code here.
Any advices are very welcome! =)