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. Test suite concept
Forum Update on Monday, May 27th 2025

Test suite concept

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtesttestsuiteautomated testi
8 Posts 2 Posters 4.0k 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.
  • ck_eeC Offline
    ck_eeC Offline
    ck_ee
    wrote on last edited by ck_ee
    #1

    Hi,

    what would be the best strategy for managing a lot of unit tests for many different libaries? I'd like to have a testsuite which can selectively run tests or simply run every test there is. My approach would be to build a single testsuite application which has a a single testmanager object which holds the unit tests objects with some kind of id/name system. This testsuite would be accesed via command line with many different options like -all or -lib "mylib" and so on. This application would of course depend on all libs that need to be tested and would include all the sources of the testcases.

    https://marcoarena.wordpress.com/2012/06/23/increase-your-qtest-productivity/ comes close to what i have in mind.

    What would be the downside to a strategy like that and are there better alternatives? I would use the QT Test framework.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Th QtTest module is not that flexible. To make it work properly you'll need a single project for every class to want to test and that will produce a binary file for each of them. You are then free to include a batch file that runs each test app based on argument passed but I'd do it outside Qt altogether

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      ck_eeC 1 Reply Last reply
      0
      • VRoninV VRonin

        Th QtTest module is not that flexible. To make it work properly you'll need a single project for every class to want to test and that will produce a binary file for each of them. You are then free to include a batch file that runs each test app based on argument passed but I'd do it outside Qt altogether

        ck_eeC Offline
        ck_eeC Offline
        ck_ee
        wrote on last edited by ck_ee
        #3

        @VRonin
        you can do a QTest::qExec(Qbject*) on your TestClasses in a simple console application

        int main() {
            int ret1 = QTest::qExec(pMyTest1);
            int ret2 = QTest::qExec(pMyTest2);
            int ret3 = QTest::qExec(pMyTest3);
        }
        
        The test classes need to have the QObject macro and the testfunctions.
        
        
        VRoninV 1 Reply Last reply
        0
        • ck_eeC ck_ee

          @VRonin
          you can do a QTest::qExec(Qbject*) on your TestClasses in a simple console application

          int main() {
              int ret1 = QTest::qExec(pMyTest1);
              int ret2 = QTest::qExec(pMyTest2);
              int ret3 = QTest::qExec(pMyTest3);
          }
          
          The test classes need to have the QObject macro and the testfunctions.
          
          
          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @ck_ee said:

          @VRonin
          you can do a QTest::qExec(Qbject*) on your TestClasses

          Unfortunately while the overall pass/fail result works that way, if you try to export the results (in xUnit format for example) you'll only get those from the last test, pMyTest3 in that example. That's why I recommend to separate them as meaningful output is the most important thing in a test imho

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          ck_eeC 1 Reply Last reply
          0
          • ck_eeC Offline
            ck_eeC Offline
            ck_ee
            wrote on last edited by ck_ee
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • ck_eeC Offline
              ck_eeC Offline
              ck_ee
              wrote on last edited by
              #6

              you could redirect the console output to a file - for example:

              myTest.exe -xml > result.xml
              
              1 Reply Last reply
              0
              • VRoninV VRonin

                @ck_ee said:

                @VRonin
                you can do a QTest::qExec(Qbject*) on your TestClasses

                Unfortunately while the overall pass/fail result works that way, if you try to export the results (in xUnit format for example) you'll only get those from the last test, pMyTest3 in that example. That's why I recommend to separate them as meaningful output is the most important thing in a test imho

                ck_eeC Offline
                ck_eeC Offline
                ck_ee
                wrote on last edited by ck_ee
                #7

                @VRonin

                i found another approach:
                http://stackoverflow.com/questions/24800912/how-to-compose-multiple-unit-test-result-in-a-single-txt-file?rq=1

                QList<QObject *> objects;
                objects << new TestSpinBox << new TestComboBox;
                
                QString result;
                foreach (QObject *o, objects) {
                    QTemporaryFile f;
                    f.open();
                    QStringList args = app.arguments();
                    args << "-o" << f.fileName();
                    QTest::qExec(o, args);
                    result += "\r\n" + f.readAll();
                }
                qDeleteAll(objects);
                

                you collect test object as i proposed but then set the output file in the argument list on a temporary file and concate that in a QString which then could be wrote anywhere you want.

                1 Reply Last reply
                1
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  That would still create an invalid xml file if you use xUnit output.
                  I use jenkins so the results should be readable from it too. Agree you can handle the xml file manually to make it valid but it looks like a lot of useless work compared to a single line in (windows) batch if you split the tests

                  for /f %%f in ('dir /b "Tests\*.exe"') do Tests\%%f -o %%f.xml,xml
                  

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  0

                  • Login

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