I have a XCTTestClass that has an asynchronous setup method. It will take some amount of time (has to parse files, insert them in a bd, etc) and I want to make sure my tests only run after this setup is done.
How can I do this?
I have a XCTTestClass that has an asynchronous setup method. It will take some amount of time (has to parse files, insert them in a bd, etc) and I want to make sure my tests only run after this setup is done.
How can I do this?
You can use semaphores to wait till you get the results back from your async call.
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
// Do your async call here
// Once you get the response back signal:
[self asyncCallWithCompletionBlock:^(id result) {
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
In your
-setup
method use either a semaphore as above or use dispatch_group. dispatch_group is my preferred approach.Then override
-invokeTest
and make sure the group blocks(setup) is done running.This guarantees that the tests will run only after
-setup
is completed.