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

Propagating failing unit tests to Qt Creator issues-pane with QTestLib



  • I recently switched from CppUnit to QTestLib for my projects, and I find making tests is faster and easier. However, I have two concerns. The first being as stated in the title. Using CppUnit I managed to get failing unit tests listed in issues-pane of Qt Creator, which also allowed me to click on it to get to the failing line. How do I set this up with Qt Creator? It is a little hideous to read the Application output/Compile output to find the failing unit tests (even though said output contains the exact same link I wish to have in Issues pane). Test runner is shown below.

    The other concern is more of a nicety, which I guess is what made test development with CppUnit so laborious: auto registering test classes (and registering them.. So many macros).
    Is there a way to do this? As of now I have to manually include their header in my my test runner, as shown below.
    This solution is not scalable....

    #include "unitmain.h"
    
    #include "firstunittest.h"
    #include "secondunittest.h"
    #include "thirdunittest.h"
    
    int UnitMain::unitMain(int argc, char *args[])
    {
        int status = 0;
        auto runTest = [&](QObject * testObject)
        {
            status |= QTest::qExec(testObject, argc, args);
            delete testObject;
        };
    
        runTest(new FirstUnitTest);
        runTest(new SecondUnitTest);
        runTest(new ThirdUnitTest);
        // repeat for all unit tests in the project...
        return status;
    }
    
    int main(int argc, char *args[])
    {
        return UnitMain().unitMain(argc, args);
    }
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK, it's a feature missing from Qt Creator. You can check that on the bug report system. If you don't find anything, you can open a new feature request for it.

    The general Qt way of unit testing is to have each test as an independent application. I don't see a really easy way to bring them all in only one executable code wise.



  • Hi, and thank you! :-)

    I'll see what I can find in the issue tracker. As for the test, do you mean that every single instance of a unit test is run in a separate executable? If I have 100+ unit tests, I end up with 100+ executables?

    EDIT:
    It seems this was proposed a long time ago
    https://bugreports.qt.io/browse/QTCREATORBUG-86


  • Lifetime Qt Champion

    Yes, each unit test gets its own executable. You can check Qt's sources, it's working quite well.

    Thanks for pointing to the request.


Log in to reply