Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    Tools
    qtcreator qtestlib
    2
    4
    1135
    Loading More Posts
    • 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.
    • B
      Borkr last edited by Borkr

      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);
      }
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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.

        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 Reply Quote 0
        • B
          Borkr last edited by Borkr

          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

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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.

            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 Reply Quote 0
            • First post
              Last post