I have a subproject in which I put all my QTest tags and create a standalone test application that runs tests (i.e., run it from Qt Creator). I have several test classes that I can execute with qExec() . However, I do not know what the correct way to execute multiple test classes is.
I am currently doing it this way (MVCE):
tests.pro
QT -= gui QT += core \ testlib CONFIG += console CONFIG -= app_bundle TEMPLATE = app TARGET = testrunner HEADERS += test_foo.h SOURCES += main.cpp
main.cpp
#include <QtTest> #include <QCoreApplication> #include "test_foo.h" int main(int argc, char** argv) { QCoreApplication app(argc, argv); TestFooClass testFoo; TestBarClass testBar; // NOTE THIS LINE IN PARTICULAR. return QTest::qExec(&testFoo, argc, argv) || QTest::qExec(&testBar, argc, argv); }
test_foo.h
#include <QtTest> class TestFooClass: public QObject { Q_OBJECT private slots: void test_func_foo() {}; }; class TestBarClass: public QObject { Q_OBJECT private slots: void test_func_bar() {}; };
However, the documentation for qExec() says this is the wrong way:
For stand-alone test applications, this function cannot be called more than once, since the command line parameters for registering test output in files and executing individual test functions will behave incorrectly.
Another significant drawback is that there is no single summary for all test classes , only for individual classes. This is a problem when I have dozens of classes, each of which has dozens of tests. To check if all the tests passed, I have to scroll up to see all the βResultsβ of what passed / failed for each class, for example:
********* Start testing of TestFooClass ********* PASS : TestFooClass::initTestCase() PASS : TestFooClass::test_func_foo() PASS : TestFooClass::cleanupTestCase() Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted ********* Finished testing of TestFooClass ********* ********* Start testing of TestBarClass ********* PASS : TestBarClass::initTestCase() PASS : TestBarClass::test_func_bar() PASS : TestBarClass::cleanupTestCase() Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted ********* Finished testing of TestBarClass *********
I am also surprised that my qExec() || qExec() qExec() || qExec() works, given that the documentation says that if the qExec() test fails, it returns a non-zero value, which should mean that all of the following qExec() calls will not be executed, but this does not seem to be the case.
What is the correct way to run multiple test classes? And so I can immediately see if any of the hundreds of unit tests I failed.