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. Unit testing with QtTest only in CLI an application that has GUI

Unit testing with QtTest only in CLI an application that has GUI

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 535 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.
  • K Offline
    K Offline
    Kuczmil
    wrote on last edited by Kuczmil
    #1

    Hello,

    I have a general question whether is it feasible to unit test an application that has GUI but the tests (testing only the "core" of the app) would be run in the environment without any desktop?

    The problem is that I have class xmlparser. That class parses xmls and then store them in the QDomDocument but if something goes wrong, static functions from QMessageBox are directly used. Due to that, I am receiving an error that QWidget or QPixmap cannot be created without QApplication. I am aware that the design of that classes is not the best.

    Option with macros like QTEST_GUILESS_MAIN is also not possible since there is one test class per tested class - so I cannot have more than one main.

    Running tests with dummy created QApplication in the CLI environment makes Qt to complain about missing X11.

    I would appreciate any suggestion.

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

      Hi,

      Exclude all widgets related stuff from that part and show your message box from your GUI. I don't know how your class is working but you can emit an signal like errorOccured and in your application show the message box. This will make your class GUI independent and easier to test.

      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
      2
      • K Kuczmil

        Hello,

        I have a general question whether is it feasible to unit test an application that has GUI but the tests (testing only the "core" of the app) would be run in the environment without any desktop?

        The problem is that I have class xmlparser. That class parses xmls and then store them in the QDomDocument but if something goes wrong, static functions from QMessageBox are directly used. Due to that, I am receiving an error that QWidget or QPixmap cannot be created without QApplication. I am aware that the design of that classes is not the best.

        Option with macros like QTEST_GUILESS_MAIN is also not possible since there is one test class per tested class - so I cannot have more than one main.

        Running tests with dummy created QApplication in the CLI environment makes Qt to complain about missing X11.

        I would appreciate any suggestion.

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @Kuczmil in addtion to @SGaist suggestion of making your class/library "GUI-less", i.e. having no widgets at all, you may want to check the xvfb virtual framebuffer X server for X Version 11. From documentation:

        Xvfb is an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory.

        Earlier Qt for Embedded version provided a virtual framebuffer which allow for simulating different displays when no actual hardware was available...
        In

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2

        • Login

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