Make unit test wait for an asynchronous call inside another method

I am testing that all my data is loaded correctly in UIViewControllerusing UITableView.

The code that loads the data and populates the table is inside myMethod()and its asynchronous call.

func myMethod() {
    reloadModel { ... wait for async callback ... }
}

In my test case, I am calling myMethod(), but I do not know how to wait for the completion of the asynchronous call.

//Test Code
func testLoadData() {
        let listVC = ListViewController.init(tableView:tableView)
        listVC .myMethod()
         ... here it should wait for the async call...
        XCTAssertEqual(...)
}
+4
source share
1 answer

, . myMethod() , ( ). , . , , -.

; , myMethod() pleaseGoGetMyData() .

, , , , - , () .

XCTestExpectation. . EridB .

+2

Source: https://habr.com/ru/post/1678457/


All Articles