I am trying to do some unit testing for the API. Here is the actual function.
func registerApi(path: String, player_id: Int, contest_id: Int, country_id: Int, success: () -> Void)
{
ServiceHelper.sharedInstance.sendRequest(path: "register-country",
params: ["api_token": Constants.USER_INFO["api_token"].rawValue,
"player_id": player_id,
"country_id": country_id,
"contest_id": contest_id],
showSpinner: true,
completionHandler:
{ (response, error) in
if (error != nil)
{
Test to be failed
}
else
{
Test Passed
}
})
}
And, now here is the test function for unit testing.
func testApiWorking()
{
let controller = WorldCupChooseCountryVC()
let expected = XCTestExpectation(description: "Some Countries to return")
controller.registerApi(path: "get-country", player_id: 163, contest_id: 1, country_id: 1) { success in if success { expected.fulfill() }
else{
XCTFail()
}
}
waitForExpectations(timeout: 1.0) { (_) -> Void in
}
}
But, whenever I try to test this I get the following error.
[UIApplication applicationState] must be used from main thread only
Once, it also ran well, the test failed, but it ran. But, it is not even running now.