I am making an POST API call. I am running the UI test and wants to check the response of the URL. But I am getting an error when I run this test.
Error:Asynchronous wait failed: Exceeded timeout of 10 seconds, with unfulfilled expectations: "messaage"
Here is my Test function which i am calling.
func testgetdata() {
let expectation = expectationWithDescription("asynchronous call waitng ")
let test:mainclass = mainclass()
test.getData(){ (response,data) in
if let HTTPResponse = response as? NSHTTPURLResponse, MIMEType = HTTPResponse.MIMEType {
XCTAssertEqual(HTTPResponse.statusCode, 200, "HTTP response status code should be 200")
XCTAssertEqual(MIMEType, "application/json", "HTTP response content type should be text/html")
} else {
XCTFail("Response was not NSHTTPURLResponse")
}
expectation.fulfill()
}
waitForExpectationsWithTimeout(10.0, handler: nil)
}
Main function:
func getData(callback: (response:NSURLResponse, data:NSData) -> ()) {
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config)
let requestURL = NSMutableURLRequest(URL: NSURL(string: "URL")!)
requestURL.HTTPMethod = "POST"
let task = session.dataTaskWithRequest(requestURL) { (data, response, error) in
print(response)
callback(response: response!,data: data!)
}
task.resume()
}