XCTest sleep () function?

I am testing an application that displays data. The part of the test that I am setting up requires storing multiple data points. I would like to do this by executing the XCTest collection method and then the sleep () function and another call to the receiving method.

While there are ways to wait for a timeout wait, there seems to be no simple wait () / sleep () method that simply pauses execution for a certain amount of time. Any idea how I can do this using Xcode 6 and Swift?

+4
source share
1 answer

You can use NSTimerto put your data calls instead of blocking the application withsleep

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 change these settings to your liking and needs.

+5

All Articles