test()
メソッドを実行する前に複数の呼び出しを行う必要があります。完成ブロックがあり、私はwaitForExpectations()
を使用しています。複数の非同期呼び出しがあるので、私はカウンタを使用しています。 expectation.fulfill()
は、カウンタがコール数に達した場合にのみ発生します。XCTestCaseのsetUp()で複数の非同期呼び出しを待機する
override func setUp() {
super.setUp()
let exp = expectation(description: "waitForSetUp")
var counter = 0
// Issue an async request
self.addEventToCalendar(title: "Test1", description: "Description test1", startDate: NSDate().addingTimeInterval(-36000), endDate: NSDate()){(success, error) in
if (success) && (error == nil) {
counter = counter + 1
if(counter == 2){exp.fulfill()}
}
}
self.addEventToCalendar(title: "Test2", description: "Description test2", startDate: NSDate(), endDate: NSDate().addingTimeInterval(36000)){(success, error) in
if (success) && (error == nil) {
counter = counter + 1
if(counter == 2){exp.fulfill()}
}
}
waitForExpectations(timeout: 40, handler: nil)
}
この構成は機能しません。 test()
メソッドは、呼び出しが返される前に実行されることがあります(必ずしもそうではありません)。
setUp()
は複数の非同期呼び出しを返すのを待つことができますか?
あなたはハンドラを実装し、起こりうるエラーをチェックしようとしましたか? – user3581248