Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Are there any techniques to fast-forward time for testing purposes in a Qt application?
Forum Updated to NodeBB v4.3 + New Features

Are there any techniques to fast-forward time for testing purposes in a Qt application?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Richard Lang
    wrote on last edited by
    #1

    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://stackoverflow.com/questions/49062286/are-there-any-techniques-to-fast-forward-time-for-testing-purposes-in-a-qt-appli

    thx

    A 1 Reply Last reply
    0
    • R Offline
      R Offline
      Richard Lang
      wrote on last edited by Richard Lang
      #5

      5 years down the track, I've built my own

      https://github.com/RichardLangFromNZ/QtFakeTime

      1 Reply Last reply
      0
      • R Richard Lang

        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://stackoverflow.com/questions/49062286/are-there-any-techniques-to-fast-forward-time-for-testing-purposes-in-a-qt-appli

        thx

        A Offline
        A Offline
        ambershark
        wrote on last edited by
        #2

        @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:

        https://www.addictivetips.com/windows-tips/set-system-clock-to-move-faster-for-app-testing-accelerify/

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        F 1 Reply Last reply
        4
        • A ambershark

          @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:

          https://www.addictivetips.com/windows-tips/set-system-clock-to-move-faster-for-app-testing-accelerify/

          F Offline
          F Offline
          Fleshbits
          wrote on last edited by
          #3

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

          jsulmJ 1 Reply Last reply
          0
          • F Fleshbits

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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @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?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Richard Lang
              wrote on last edited by Richard Lang
              #5

              5 years down the track, I've built my own

              https://github.com/RichardLangFromNZ/QtFakeTime

              1 Reply Last reply
              0
              • R Richard Lang has marked this topic as solved on

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved