Are there any techniques to fast-forward time for testing purposes in a Qt application?
-
Using Qt for developing a system that in various places involves time based state transitions. I'm trying to put in place comprehensive unit testing coverage as I go, and obviously trying to provide thorough automated testing of state transitions that occur over multiple second or even minute periods is severely suboptimal.
In the past, when dealing with the same challenges for "bare metal" C and RTOS based embedded systems, I've successfully implemented hook functions that have allowed the fast-forwarding/acceleration of passing time for testing purposes, and am wondering if anyone out there has come across any techniques for achieving the same in Qt (developer APIs, shim libraries etc)
The state transitions in question may trigger from a combination of QTimer timeouts, examination of QDateTime/QElapsedTimer/QDeadlineTimer timestamps and QThread sleeps, so a simple fake of QTimer::timeout signals is not enough.
Not really needing the usual suggestions regarding dependency injection of mockable timers, interfaces that allow configurable timeouts, or hanging custom test facilitating facade/decorators over the entirety of the Qt library time related classes. I'm well aware of how I could do this, I'm hoping that I don't have to...
thx
-
5 years down the track, I've built my own
-
@Richard-Lang I know you don't want to hear it but the answer for testing stuff like this is mocking. That really is the whole point of mocking. Otherwise what I do in these situations is change my timeouts and such based on a debug setting. That way I can speed things up to quickly test while developing but without those -D flags to the build, they run at normal time.
That being said a quick google turned this up which may be something you're looking for:
-
@ambershark said in Are there any techniques to fast-forward time for testing purposes in a Qt application?:
@Richard-Lang I know you don't want to hear it but the answer for testing stuff like this is mocking. That really is the whole point of mocking.
I want to hear it. In fact, I am Googling the hell out of it and ended up here. Can we get a minimal code example? I have no idea how to go about mocking QTimer. It's not like it is as simple as overriding a "getTimeElapsed" method and calling it a day. It has to fire signals and connect to slots.
-
@Fleshbits said in Are there any techniques to fast-forward time for testing purposes in a Qt application?:
I have no idea how to go about mocking QTimer
Why do you want to mock QTimer?
-
5 years down the track, I've built my own
-