0
我只是有一個方法:如何測試在主線程上運行異步的方法?
func update(with process: PresentableProcess) {
presentableProcess = process
if isViewLoaded {
DispatchQueue.main.async { [weak self] in
//do sth on the main thread
}
}
}
及其試驗:
func testPreferredContentSizeWhenTitleExist() {
let process = PresentableProcess(title: "title")
sut.update(with: process)
XCTAssertEqualWithAccuracy(sut.preferredContentSize, 95, accuracy: 10)
}
它不工作,因爲在主線程上運行...我想,以避免update(with)
將完成塊考試及格。