Razvan Baraboi
Razvan Baraboi

Reputation: 223

How to change date and time on simulator when using XCUITest

I need to automate some UI tests and I have to assert some results that only occur if changing the date on the simulator to a few days the future. Does anyone know any way of doing that on the simulator without having to change the date on my mac or without using xcodebuild command line? I need to be able to change the date multiple times during my tests using different values each time.

Upvotes: 2

Views: 828

Answers (1)

Oleg
Oleg

Reputation: 801

The only way for you to test it on your app is to create an Date wrapper

class DateWrapper {
   func currentDate() -> Date {
      return Date()
   }
}

and mock currentDate() function according to your test.

Upvotes: 1

Related Questions