简体   繁体   English

从xctest执行dispatch_async(dispatch_get_main_queue()

[英]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. 我正在尝试编写测试,该测试使用OHHTTPStubs对请求进行存根,然后应加载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. 存根部分正在工作,但是问题是,测试和UI加载都在主线程上执行,因此此加载ViewController的块永远不会执行。 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]];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 dispatch_async(dispatch_get_main_queue(),^ {}); 从iOS7背景线程慢 - dispatch_async(dispatch_get_main_queue(), ^{}); from Background Thread slow on iOS7 调用dispatch_async(dispatch_get_main_queue())时UIView屏幕冻结 - UIView screen freeze when calling dispatch_async(dispatch_get_main_queue()) 在什么情况下dispatch_async(dispatch_get_main_queue(),^ ...什么都不做 - Under what circumstances does dispatch_async(dispatch_get_main_queue(), ^ … do nothing 使用“ dispatch_async(dispatch_get_main_queue(),^ {block})更新UI - Updating the UI using "dispatch_async(dispatch_get_main_queue(),^{block}) NSMutableURLRequest超时后未触发dispatch_async(dispatch_get_main_queue() - dispatch_async(dispatch_get_main_queue() not firing after NSMutableURLRequest with timeoutInterval 嵌套dispatch_async(dispatch_get_main_queue()^ {})的目的是什么? - What is the purpose of nesting dispatch_async(dispatch_get_main_queue()^{}) ? 使用dispatch_async + dispatch_get_main_queue进行UI更新有什么意义? - What's the point in using dispatch_async + dispatch_get_main_queue for UI updates? 直接执行方法与在dispatch_async(dispatch_get_main_queue(),^ {})块中有什么区别 - What is the difference between perform a method directly and in the block of dispatch_async(dispatch_get_main_queue(), ^{}) NSManagedObjectContext中的dispatch_async(dispatch_get_main_queue()在performBlock中 - dispatch_async(dispatch_get_main_queue() inside NSManagedObjectContext performBlock dispatch_async(dispatch_get_main_queue(),^ {...});等到完成? - Does dispatch_async(dispatch_get_main_queue(), ^{…}); wait until done?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM