Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCTest sleep() function?

I am testing an app which samples data. Part of the test I am setting up requires a few data points to be stored. I would like to do this by having XCTest execute the acquisition method followed by a sleep() function and yet another call to the acquisition method.

Though there are methods to wait for an expectation with timeout, there doesn't seem to be a simple wait()/sleep() method that simply pauses execution for specified amount of time. Any idea how I can do this using Xcode 6 and Swift?

like image 952
Yohst Avatar asked Dec 21 '25 21:12

Yohst


1 Answers

You can use NSTimer to space out your data calls instead of locking up the app with sleep

func dataCall(timer : NSTimer) {

   // get data
}
let myTimer : NSTimer = NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: Selector("dataCall:"), userInfo: nil, repeats: false)

and of course you can alter those parameters to your liking and needs.

like image 60
Cole Avatar answered Dec 23 '25 09:12

Cole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!