Using QTest for GUI testing

  • Moderators

    I started to use QTest for GUI testing. At first I tested basically similar to any application some setters and getters for the widget to be tested. Since the widget shall be embedded into a dialog, I used a little test dialog for an event loop. This allows also to test some GUI stuff (changing in QComboBox, etc.).

    Finally I looked up the possibility to test out the gui with some keystrokes for a starter. The tutorial seems to be fairly easy to follow. I have added a routine testGui to my widget and call it through the Dialog used as noted above. The intensional introduced error in the testGui routine of the widget did not trigger anything.

    Therefore, I checked the tutorial and saw the need to include .moc file. As a starter I thought about including the widget moc file in addition to the tst.moc as it is typically with those test applications. However, I cannot find a generated .moc for my widget.
    Running qmake and rebuild all did not bring such a .moc (only the tst*.moc is present). Checking the compile output shows that the moc is not called for the widget, but the dialog and the widget as its content is working.

    I always thought the proper operation of moc is required for dialogs and widgets.

    Anyone has an explanation?

  • Moderators


    Basically two problems on my side.

    .moc is not generated for every dialog as I thought. I got confused by name convention. moc_*.cpp are being produced.

    However, I had made another stupid error before. Accidently I had placed my test code into the contructor of the testing class and not in the routine testCase1() as required. However, since I had no problems from the being, I did not pay attention to this details. After moving the code to testCase1() also the test returns from my widget are monitored.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.