In the IOS test case, after I tap the button I use CFRunLoopRunInMode(mode, 3, false)
to wait for the UI changes(a new ViewController will appear), and then I tap the item in new ViewController. The question is the 2nd ViewController sometimes can not appear in 3s, and I want to determine the exact loading time of ViewController then I will continue to run the case immediately.
The test case like below:
[btn tap];
CFRunLoopRunInMode(mode, 3, false);
[btn2 tap];// if ViewController not loaded at this time then will crash there
Possible solution:
- Polling
Use a loop to determine whether a view controller is loaded.
[btn tap];
fullfilled = NO;
while(!fullfilled){
CFRunLoopRunInMode(mode, 0.3, false);
fullfilled = determineControllerMethod("viewControllerName");
}
[btn2 tap];
- XCTestExpectation
It can only use in test case while I also want to determine in normal NSObject method. XCTestExpectation can only fail with a timeout.
Are there other good methods worth to try? Thank you a lot if you can put some tips here.
Aucun commentaire:
Enregistrer un commentaire