2

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...

Duped at https://forum.qt.io/topic/88268/are-there-any-techniques-to-fast-forward-time-for-testing-purposes-in-a-qt-application

thx

Richard Lang
  • 456
  • 4
  • 15
  • I m not into the QT framework, so just a thought here: in Java, one way of getting *around* such problems is to rely on a "same thread service" (see https://stackoverflow.com/questions/6581188/is-there-an-executorservice-that-uses-the-current-thread ). The whole point there: for testing purpose, you turn a multi-threaded problem ... into a single threaded one. And then your single thread can first *set* some condition, which then gets **immediately* afterwards processed. – GhostCat Mar 02 '18 at 09:58

1 Answers1

0

5 years later, I've built my own

https://github.com/RichardLangFromNZ/QtFakeTime

Richard Lang
  • 456
  • 4
  • 15