Qt: How to organize Unit Test with more than one class?

后端 未结 6 1532
温柔的废话
温柔的废话 2020-12-29 03:10

I have a Qt Unit test (sub)project, which generates me one class (with the main generated by QTEST_APPLESS_MAIN).I can start this from within Qt Creator as cons

6条回答
  •  春和景丽
    2020-12-29 03:27

    I'm using the following code to collect all test results:

    #include "testclassa.h"
    #include "testclassb.h"
    #include 
    #include 
    
    int main(int argc, char** argv){
    
        int failedTests = 0;
        TestClassA testClassA
        TestClassB testClassB
        failedTests += QTest::qExec(&testClassA, argc, argv);
        failedTests += QTest::qExec(&testClassB, argc, argv);
    
        if(failedTests > 0){
            qDebug() << "total number of failed tests: " << failedTests;
        }else{
            qDebug() << "all tests passed :)";
        }
        return failedTests;
    }
    

提交回复
热议问题