Reputation: 750
I have created a unit test case for test the function which i handle API requests.
Bellow i have mentioned the XC test case code
var expectation:XCTestExpectation?
func testRequestFunction () {
expectation = self.expectationWithDescription("asynchronous request")
let test = HVRequest.init(subdomain: "staging", token: "jijfio88fhu0387fh", type: .GET, command: "estm") {
(success) -> Void in
}
test.request()
self.waitForExpectationsWithTimeout(30, handler: nil)
}
When i run this test case, it gives an error
Asynchronous wait failed: Exceeded timeout of 30 seconds, with unfulfilled expectations: "asynchronous request".
How ever it shows the response JSON object with the error.
Please help me to fix the issue
Upvotes: 1
Views: 4369
Reputation: 10327
The XCTestExpectation
is waiting. You have to fulfill
when you get the respond (mean: say with expectation
that I get the respond, go ahead).
let test = HVRequest.init(subdomain: "staging", token: "jijfio88fhu0387fh", type: .GET, command: "estm") {
(success) -> Void in
expectation.fulfill() // add this line
}
test.request()
Upvotes: 3