Autotest doesn't find any tests ("Test Results" window is empty)



  • I have a project and a test project, the latter building separate executable, with main looking roughly like this:

    #include "before_system_headers.h"
    #include <QtTest/QtTest>
    #include "after_system_headers.h"
    
    #include "part1/test_part1.h"
    #include "part2/test_part2.h"
    #include "part3/test_part3.h"
    //...
    
    int main(int argc, char** argv) {
        int status = 0;
    
        status |= test_part1();
        status |= test_part2();
        status |= test_part3();
        //...
        return status;
    }
    

    And test_part1() looks like this (for some parts, there are several levels, but I don't think it matters):

    #ifndef TEST_PART_1
    #define TEST_PART_1
    #include "before_system_headers.h"
    #include <QtTest/QtTest>
    #include "after_system_headers.h"
    
    #include "test_class1.h"
    //...
    
    int test_pod(void) {
       int status = 0;
       {
          TestClass1 test;
          status |= QTest::qExec(&test, 0, {});
       }
       //...
    
       return status;
    }
    #endif // TEST_PART1
    

    Finally, test_class1.h follows guidelines from test tutorial:

    #ifndef TESTCLASS1_H
    #define TESTCLASS1_H
    
    #include "before_system_headers.h"
    #include <QtTest/QtTest>
    #include <QObject>
    #include "after_system_headers.h"
    
    class TestClass1 : public QObject
    {
        Q_OBJECT
    public:
        explicit TestClass1 (QObject *parent = nullptr);
    signals:
    
    private slots:
        void test1(void)const;
        void test2(void)const;
        void test3(void)const;
        //...
    };
    
    #endif // TESTCLASS1_H
    

    When I build test project and run console application, it outputs all test results properly. But as a number of tests increases, finding which one went wrong becomes increasingly difficult (especially since tested classes have their own console output with numerous warnings). Qt documentation shows, however, that tests may be displayed in "Test Results" window. But in my case, there's exactly nothing there and command "Rescan Tests" has no effect.
    So, my questions are: what am I doing wrong and what can I do to view test results in some more clear form?


  • Lifetime Qt Champion

    Hi,

    AFAIK, this document talks about QTest tests and Google Test tests. I don't know how yours fit in these two possibilities.



  • @SGaist I'm using QTest (with private slots which are, as far as I understand, automatically found by moc and executed on QTest::qExec()).



  • I don't know if the auto-test plugin is enabled by default. Can you check Help -> Plugins?


  • Lifetime Qt Champion

    @Abstraction Your test code doesn't look like QtTest unit tests as generated by Qt Creator or that you can see in the examples hence my question and maybe why you don't get the output you are expecting (but that's only a guess)



  • I've partialy analysed AutoTest code.
    For QTest it checks if given source file (after macro preprocesing) has QTest include and QTest::exec() somewhere in code.
    In my case it lead to usage of TestRunner modified to store function object

    #define DECLARE_TEST_RUNNER(className)  \
      namespace { \
        int executeTestClass(int argc, char* argv[]) \
        { \
          className test; \
          return QTest::qExec(&test, argc, argv); \
        }; \
        static char test_##className = \
            TestRunner::Instance().RegisterTestClassRunner(executeTestClass); \
      }
    

    Macro is placed at begining of each CPP file with test details (to decouple as much as possible)

    However Autotest still acts strangely. Sometimes it discover tests, sometimes not. I believe that it may search in source context of currently selected run target.

    PS: When I expanded one of DECLARE_TEST_RUNNER macro - AutoTest start displaying green arrows. Not before. Building main exe or ut.exe isn't helping.
    Calling 'Refresh test' from Tools->Tests also doesn't help. I still don't know what triggers test gathering.
    PSS: In each test binary at least one QTest::qExec should be expanded out of MACRO. From this point - AutoTest shows also test runners hidden in MACRO and run then all.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.