I have a test that in it I have to do a REST call, to a server, and only after that call is recieved I can continue with the rest of the tests, I cannot use sleep(x)
as it will block the main thread, and won't let the rest call to be done.
here is a code example to better explain:
let homeInteractor: HomeInteractor = HomeInteractor ()
homeInteractor.initSDK()
//// <<<<< DO A DELEY HERE FOR 5 SECONDS
//sleep(5) < CANNOT USE SLEEP AS IT WILL BLOCK THE MAIN THREAD
let loginInteractor: LoginInteractor = LoginInteractor ()
let loginViewController: LoginTableViewController = LoginTableViewController ()
let loginPresenter: LoginPresenter = LoginPresenter(controller: loginViewController)
loginPresenter.onLoginButtonPressed(usernameText: "username", passwordText: "password")
waitForExpectations(timeout: 10)
XCTAssertEqual(loginPresenter.didUserLogin, true)
How can such a delay be achieved?
Aucun commentaire:
Enregistrer un commentaire