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. QTest, how to aggregate all my unit tests in one main test?
Forum Updated to NodeBB v4.3 + New Features

QTest, how to aggregate all my unit tests in one main test?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 804 Views 1 Watching
  • 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.
  • mbruelM Offline
    mbruelM Offline
    mbruel
    wrote on last edited by aha_1980
    #1

    Hi,
    Is there a way to run all the unit tests from one main test project?
    I thought I could do this kind of thing in the main.cpp

    #include <QtTest/QtTest>
    #include "Test1.h"
    #include "Test2.h"
    
    QTEST_MAIN(Test1)
    #include "moc_Test1.cpp"
    
    QTEST_MAIN(Test2)
    #include "moc_Test2.cpp"
    

    but no, in fact, QT_MAIN redefine the main....

    So I've done this for now:

    #include "Test1.h"
    #include "Test2.h"
    #include "moc_Test1.cpp"
    #include "moc_Test2.cpp"
    #include <QTest>
    int main(int argc, char *argv[])
    {
        QTEST_SET_MAIN_SOURCE_PATH
    
        Test1 t1;
        QTest::qExec(&t1, argc, argv);
    
        Test2 t2;
        QTest::qExec(&t2, argc, argv);
        return 0;
    }
    

    The "problem" is that the test results are not together. Is there a way to aggregate them?
    I'm having this at the moment:

    ********* Start testing of Test1 *********
    Config: Using QtTest library 5.10.1, Qt 5.10.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160406 (Red Hat 5.3.1-6))
    PASS   : Test1::initTestCase()
    PASS   : Test1::test_cache_withoutDeleteQueue()
    PASS   : Test1::test_cache_deleteQueue()
    PASS   : Test1::cleanupTestCase()
    Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 4640ms
    ********* Finished testing of Test1 *********
    ********* Start testing of Test2 *********
    Config: Using QtTest library 5.10.1, Qt 5.10.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160406 (Red Hat 5.3.1-6))
    PASS   : Test2::initTestCase()
    PASS   : Test2::test_createActiveRequests()
    PASS   : Test2::cleanupTestCase()
    Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 0ms
    ********* Finished testing of Test2 *********
    

    I'd like to be able to generate the sum up at the end, something like this:
    Number of Tests: 2
    Number of Tests Passed: 2
    Number of Tests Failed: 0
    (Total number of unit tests: 7)

    And in case there are some Test Failed being able to give the list

    mbruelM 1 Reply Last reply
    0
    • mbruelM mbruel

      Hi,
      Is there a way to run all the unit tests from one main test project?
      I thought I could do this kind of thing in the main.cpp

      #include <QtTest/QtTest>
      #include "Test1.h"
      #include "Test2.h"
      
      QTEST_MAIN(Test1)
      #include "moc_Test1.cpp"
      
      QTEST_MAIN(Test2)
      #include "moc_Test2.cpp"
      

      but no, in fact, QT_MAIN redefine the main....

      So I've done this for now:

      #include "Test1.h"
      #include "Test2.h"
      #include "moc_Test1.cpp"
      #include "moc_Test2.cpp"
      #include <QTest>
      int main(int argc, char *argv[])
      {
          QTEST_SET_MAIN_SOURCE_PATH
      
          Test1 t1;
          QTest::qExec(&t1, argc, argv);
      
          Test2 t2;
          QTest::qExec(&t2, argc, argv);
          return 0;
      }
      

      The "problem" is that the test results are not together. Is there a way to aggregate them?
      I'm having this at the moment:

      ********* Start testing of Test1 *********
      Config: Using QtTest library 5.10.1, Qt 5.10.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160406 (Red Hat 5.3.1-6))
      PASS   : Test1::initTestCase()
      PASS   : Test1::test_cache_withoutDeleteQueue()
      PASS   : Test1::test_cache_deleteQueue()
      PASS   : Test1::cleanupTestCase()
      Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 4640ms
      ********* Finished testing of Test1 *********
      ********* Start testing of Test2 *********
      Config: Using QtTest library 5.10.1, Qt 5.10.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160406 (Red Hat 5.3.1-6))
      PASS   : Test2::initTestCase()
      PASS   : Test2::test_createActiveRequests()
      PASS   : Test2::cleanupTestCase()
      Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 0ms
      ********* Finished testing of Test2 *********
      

      I'd like to be able to generate the sum up at the end, something like this:
      Number of Tests: 2
      Number of Tests Passed: 2
      Number of Tests Failed: 0
      (Total number of unit tests: 7)

      And in case there are some Test Failed being able to give the list

      mbruelM Offline
      mbruelM Offline
      mbruel
      wrote on last edited by mbruel
      #2

      Ok in fact the return of QTest::qExec kind of give the number of Failed Unit Tests.
      So we can do manually something like this:

      int main(int argc, char *argv[])
      {
          QTEST_SET_MAIN_SOURCE_PATH
      
          QList<QString> failedTests;
          ushort nbTests = 0, nbTestsOK = 0, nbTestsKO = 0;
          uint nbFailedUnitTests = 0;
      #ifdef __Launch_Test1__
          {
              Test1 test;
              int res = QTest::qExec(&test, argc, argv);
              qDebug() << "[Test1] QTest::qExec return: " << res;
              if (res == 0)
                  ++nbTestsOK;
              else
              {
                  ++nbTestsKO;
                  failedTests << "Test1";
              }
              ++nbTests;
              nbFailedUnitTests += res;
          }
      #endif
      #ifdef __Launch_Test2__
          {
              Test2 test;
              int res = QTest::qExec(&test, argc, argv);
              qDebug() << "[Test2] QTest::qExec return: " << res;
              if (res == 0)
                  ++nbTestsOK;
              else
              {
                  ++nbTestsKO;
                  failedTests << "Test2";
              }
              ++nbTests;
              nbFailedUnitTests += res;
          }
      #endif
          qDebug() << "\n\n\n\n";
          qDebug() << "###############################################";
          qDebug()  << "# Overall Tests Results:";
          qDebug() << "#     - number of macro Tests: " << nbTests;
          qDebug() << "#     - number of macro Tests OK: " << nbTestsOK;
          qDebug() << "#     - number of macro Tests FAILED: " << nbTestsKO;
          if (!failedTests.isEmpty())
          {
              qDebug() << "#     - number of Unit Tests FAILED: " << nbFailedUnitTests;
              qDebug() << "# List of FAILED macro Tests: " << failedTests.join(", ");
          }
          qDebug() << "###############################################";
      
          return 0;
      }
      

      we just can't have the global number of unit tests that have been run...
      bit a shame but I'll live with it ;)

      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