When making unit tests for objective C, how do you test blocks?

I have a function (internally uses ASIHTTPRequest) which calls a block with the result:

[Http get:@"http://api.geonames.org/postalCodeLookupJSON"
   params:params cacheMins:0 complete:^(NSDictionary *response, BOOL success) {
       STAssertTrue(success, @"JSON retrieved OK");
       STFail(@"blah");
}];

I want to test the above, but it seems the test doesn't get called.

How can i ensure that the test waits till the block is called?

-edit-

Of course i don't recommend to do this in the main app in the gui thread, in this particular situation it is only for a unit test.

11
задан Chris 14 September 2011 в 11:07
поделиться