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. How should I unit test my QStateMachine?

How should I unit test my QStateMachine?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 763 Views
  • 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.
  • C Offline
    C Offline
    Cletus87408
    wrote on last edited by Cletus87408
    #1

    Howdy. Long time C++ programmer but still new to Qt.

    I have developed a QStateMachine derived class that I would like run from a purely unit test environment - that is, from a standalone test class. It's not clear to me how I should do that.

    The unit test environment is MSTest, and no, we will not be replacing it with QTest any time soon. I understand that I need an event loop to drive transitions in a QStateMachine. Looking for examples of creating a standalone QEventLoop or QCoreApplication hasn't really clarified the issue - this seems to be an unusual request. I don't want to muddy the water here with shotgun guesses, so I'll just shut up now.

    Any good ideas? Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I don't know MSTest but you can still follow the QTest model: create a single class that will instantiate your QStateMachine and mock whatever system should be connected to the machine and trigger the various state.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        I don't know MSTest but you can still follow the QTest model: create a single class that will instantiate your QStateMachine and mock whatever system should be connected to the machine and trigger the various state.

        C Offline
        C Offline
        Cletus87408
        wrote on last edited by Cletus87408
        #3

        @SGaist Thanks.

        The state machine is driven by QStateMachine::postEvent() calls. When I call QStateMachine::start() and then check isRunning(), I get false. My assumption so far has been that I need to instantiate an event loop somehow to pump the transition events because the unit test environment is not running within a Qt app. Am I wrong?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          One possible way would be to have a QThread and use the worker object approach.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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