Pattern for unit testing async queue that calls main queue on completion

后端 未结 6 515
慢半拍i
慢半拍i 2020-12-04 14:52

This is related to my previous question, but different enough that I figured I\'d throw it into a new one. I have some code that runs async on a custom queue, then executes

6条回答
  •  攒了一身酷
    2020-12-04 15:07

    The simplest way to execute blocks on the main queue is to call dispatch_main() from the main thread. However, as far as I can see from the docs, that will never return, so you can never tell if your test has failed.

    Another approach is to make your unit test go into its run loop after the dispatch. Then the completion block will have a chance to execute and you also have the opportunity for the run loop to time out, after which you can deem the test failed if the completion block has not run.

提交回复
热议问题