I have the following setup. I have a object called "View" in which I want to unit test a method which contains two dispatch_async calls with in it.
view.m
typedef void (^onTaskCompletion)(); //defining the block
-(void) viewdidLoad
{
onTaskCompletion block = ^{
// callback into the block };
[self test1:block];
}
-(void) test1:(onTaskCompletion) block
{
//do something
dispatch_async(queue, ^{
// dispatch async into serial queue & do something
dispatch_async(dispatch_get_main_queue){
// calling the block
block();
};
};
}
When I run the IOS APP , the block in -(void) viewdidLoad gets called. Works perfectly fine. But the problem I have is this:
in Tests : XCTestCase (.m fie)
@property (retain) View *view;
-(void) testMyCode
{
onTaskCompletion block = ^{
// Never gets called.
};
[view test1:block];
}
When I try to Unit test this method test1(), The block never gets called.
Note: The break point within test1() method inside the dispatch_get_main_queue() never gets hit when running in test mode but does get hit when I just run the app. Any thoughts as to why it works when the app is run normally but not when running unit tests?