[英]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.