简体   繁体   中英

Execute dispatch_async(dispatch_get_main_queue() from xctest

I am trying to write test, that stubs the requests with OHHTTPStubs and then it should load the UI. The stub part is working, but the problem is, that test and UI loading are both executed on the main thread, so this block of loading ViewController never gets executed. Thanks for the tips in advance. Have a great day.

dispatch_block_t mainBlock = ^{
        WDSomeVC *viewController = [[WDSomeVC alloc] initWithData:data andStyle:self.style];
        viewController.delegate = self;
        [self switchRootController:viewController withCompletion:nil];
};
dispatch_async(dispatch_get_main_queue(), mainBlock);

我用这段代码解决了。

 [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:timeToWait]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM