I was having some trouble unit testing some grand central dispatch code with the built in Xcode unit testing framework, SenTestingKit. I managed to boil my problem done to this. I have a unit test that builds a block and tries to execute it on the main thread. However, the block is never actually executed, so the test hangs because it's a synchronous dispatch.
- (void)testSample {
dispatch_sync(dispatch_get_main_queue(), ^(void) {
NSLog(@"on main thread!");
});
STFail(@"FAIL!");
}
What is it about the testing environment that causes this to hang?
dispatch_sync(dispatch_get_main_queue()
while on the main thread won't create dead lock!? – Honey