0

I'm looking for a way to vary (speed up) the clock for unit tests, so automated tests don't need to wait too long for time- or timer-dependent events to happen. Other frameworks sometimes provide e.g. "mock clocks", but I couldn't find anything alike for the QTest framework. Only speeding up the "event flow" for QTimer/QSingleShotTimer instead of the entire application would also work for me for the moment.

Just for QTimer it seems that one could simulate QTimerEvents, sending them to specific QTimer objects. But catching the initial call to startTimer() seems to be more complex. Also QTimer creates QSingleShotTimer objects internally for single-shot events, and one would need to get a handle on these, as well. Thus, it doesn't really look viable to me.

I'd appreciate any hints or help in these regards. Maybe I'm using all the wrong search terms, but couldn't find anything related to "manipulating timing" in the Qt docs or forums (or any web search results). Thanks a lot in advance!

jpw
  • 56
  • 3
  • Possible duplicate of [Controlling time of QTimer?](https://stackoverflow.com/questions/40401863/controlling-time-of-qtimer) – cerkiewny Mar 08 '19 at 14:36
  • You can access to the timer outside and change its interval. But, why can't you just call the slot connected to your timer in your unit test? – Dimitry Ernot Mar 09 '19 at 17:31
  • @cerkiewny The solutions in the other thread see quite intrusive. I couldn't come up with something less intrusive and "more generally applicabl", hence my question here. Those might be the fallbacks though. Furthermore, in an ideal world I'd be able to control QSingleShotTimer/QBasicTimer/(QTimerEvent) as well ... – jpw Mar 12 '19 at 12:06
  • 1
    @Romha I'd like a solution which is applicable to existing source code which might (possibly) encapsulate the QTimer objects, their parameters and respective slots privately. Meaning, my question here aims at a way to avoid modification of the tested code. Often some adjustments to the tested code might be easier, but sometimes not - those cases I'd like to cover. – jpw Mar 12 '19 at 12:09

0 Answers0