In unit test, execute the block passed in queue with dispatch_asyc
问题 If I dispatch_async a block on main queue like this: -(void) myTask { dispatch_async(dispatch_get_main_queue(), ^{ [self.service fetchData]; }); } In unit test, I can execute the block passed in main queue by manually run the main loop like this: -(void)testMyTask{ // call function under test [myObj myTask]; // run the main loop manually! [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]; // now I can verify the function 'fetchData' in block is called ... } Now