XCTest and asynchronous testing in Xcode 6

后端 未结 4 1204
情深已故
情深已故 2020-11-30 03:32

So Apple said in the release note of Xcode 6 that we can now do asynchronous testing directly with XCTest.

Anyone knows how to do it using Xcode 6 Beta 3 (Using obj

4条回答
  •  醉梦人生
    2020-11-30 04:22

    How I did in swift2

    Step 1: define expectation

    let expectation = self.expectationWithDescription("get result bla bla")
    

    Step 2: tell the test to fulfill expectation right below where you capture response

    responseThatIGotFromAsyncRequest = response.result.value
    expectation.fulfill()
    

    Step 3: Tell the test to wait till the expectation is fulfilled

    waitForExpectationsWithTimeout(10)
    

    STep 4: make assertion after async call is finished

    XCTAssertEqual(responseThatIGotFromAsyncRequest, expectedResponse)
    

提交回复
热议问题