【发布时间】:2020-06-17 13:24:36
【问题描述】:
我是第一次进行单元测试,但我对一些特定情况感到迷茫。
尽管阅读了很多书,但我对如何在 iOS 中测试这样的功能感到困惑:
func myFunction() {
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
// Tasks to do in background
dispatch_async(dispatch_get_main_queue(), ^(void){
// Get the results
// Update UI
});
});
}
我读过“期望”(https://developer.apple.com/documentation/xctest/asynchronous_tests_and_expectations/testing_asynchronous_operations_with_expectations?language=objc),但我不知道如何使用它们。我想我应该打电话给 expect.fulfill(),但我不知道在哪里。
【问题讨论】:
标签: ios unit-testing dispatch-async expectations