Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



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


  • Lifetime Qt Champion

    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.



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


Log in to reply