Question

When running tests using SenTestingKit, they don't fail correctly inside a block, e.g.

operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                            success:^(NSURLRequest *req, NSHTTPURLResponse *response, id jsonObject){
                                                                STFail(@"This does not fail");
                                                            }
                                                            failure:^(NSURLRequest *req, NSHTTPURLResponse *response, NSError *error, id jsonObject){
                                                                STFail(@"Neither does this");
                                                            }];
[operation start];
STFail(@"But this fails fine");

What am I missing?

Was it helpful?

Solution

The trouble is that you have an asynchronous call. Which means that the it returns immediately and your last STFail is hit.

There are solutions to be had. How to unit test asynchronous APIs?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top