Make a unit test wait for a async call inside another method

Viewed 1648

I'm testing that all my data are correctly loaded in a UIViewController with a UITableView.

The code loading the data and populating the table is inside myMethod() and its an an async call.

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

In my Test Case, I'm calling myMethod(), but I don't know how to wait for the async call to complete.

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