I searched for a while, but couldn’t find the same question.
I am writing an application where I need to schedule a lot of alarms a day, and then do different things throughout the day, and I’d love to be able to test, say 24 hours in 24 minutes, or something along those lines.
Is it possible to simulate a faster passage of time, either in emulator, or on-device?
If it is, this would be great for me to be able to test these things without losing development time. As it is, I’m writing them in a way that I think will work, doing spot tests, and then running the program myself to verify that the behavior is correct, but it greatly slows my development time to have to wait a day or two between seeing a poor behavior, and then trying to fix it and retesting it. Any help would be greatly appreciated!
If you abstract all time-dependent tasks into a single class, you could inherit that into a test-class, where all system times are multiplied by some constant, and all user times are divided by some constant. Instead of calling any time-dependent methods directly, you call it trough this class.
UPDATE
You could make the
RATEandSTART_TIMEconstants into instance fields. Maybe even constructor arguments.Example usage:
If you can’t control the actual scheduling of the alarms, I don’t think there is any way to compress the time. You will have to use these classes to schedule the alarms when you are reading it from the database.