私は単純にメソッドを持っている:メインスレッドでasyncを実行するメソッドをテストするには?
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)
}
それdoesntの仕事、メインスレッド上で実行され...私はにupdate(with)
に完了ブロックを追加しないようしたいと思いますので、検査を通る。