2

I need to write automated tests for an iOS application in various scenarios. An important test case is when the app is launched in specific times of day (day vs night) and in specific dates (user's birthday, year seasons etc.).

Adding a mock object in the application's code itself is not a good option. Also, I know the device time can be changed manually via Preferences App, but the tests must be fully automated. I also know the settimeofday is restricted in iOS sandboxed application.

I was hoping to be able to set the application's time inside my XCUITestCase, in such a way that only the application under test would be affected (for sake of security).

Is this doable? Or should I submit a feature request to Apple?

Thanks!

Community
  • 1
  • 1
Elist
  • 5,313
  • 3
  • 35
  • 73
  • I think you need to modify your app for testability; ensure that the current date is obtained from a mockable object, or perform unit tests on the expected behaviour of functions that accept a date, you can then pass the appropriate date and look for the correct return value. – Paulw11 Mar 23 '17 at 21:28
  • 1
    I am hoping to avoid that kind of changes... Plus I don't control the source code and can only add UI Tests. – Elist Mar 23 '17 at 21:33
  • If you are testing on a simulator then you can probably use a script to change the date/time on the underlying Mac, but it really seems that the code needs to be changed to be adequately testable. If it has behaviour that depends on date/time and has not been architected so that date/time can be mocked or a specific date injected into unit tests then the design is deficient from a testability point of view. – Paulw11 Mar 23 '17 at 21:36
  • 1
    I would look into the Simulator idea, Good point. You could argue that the design is deficient (I would argue that almost every feature in XCTest framework could be in-app mocked, yet the framework still exist for a reason), but that's the problem I should deal with... thanks anyway. – Elist Mar 23 '17 at 21:46

0 Answers0