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.
Asked
Active
Viewed 482 times
2
-
It would be easier if you used unit tests because then you can easily add methods that change the used date in your code. Could you change theses tests to be unit tests? – dasdom Oct 13 '20 at 14:34
1 Answers
1
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.

Oleg
- 591
- 5
- 14
-
1Please avoid using NS... types when there are corresponding native swift types. And why is the return type forced unwrapped? – Joakim Danielson Oct 13 '20 at 13:31