How to run multiple tests in Qt without calling QTest::qExec multiple times?

851 Views Asked by At

I have a project with multiple independent libraries, and for each library I wish to create it's own test suite. I plan to have a single executable that links all suites, and to be able to run either all tests or a single test from the Qt Creator Test window. How to do that?

The basic Qt tutorial considers only the case where a single test object is being created, and one of the macros QTEST_MAIN, QTEST_APPLESS_MAIN or QTEST_GUILESS_MAIN is used.

There are advices like this and that where the main function is created manually and the QTest::qExec function is called multiple times. This solution doesn't work anymore (or at least I failed to solve my problem in this way), as the QTest::qExec function shall not be called more than once:

For stand-alone test applications, this function should not be called more than once, as command-line options for logging test output to files and executing individual test functions will not behave correctly.

How to use several test objects in a single executable? What are the idiomatic/recommended ways to develop tests in Qt where the tests cannot share the same object with a single initTestCase/cleanupTestCase pair?

I'm using Qt 5.14.0 with Qt Creator 4.11.0 + QMake. The OS is Windows.

Note! I've already asked this question before, but it was mistakenly closed as duplicated with How to run multiple QTest classes?. Pay special attention to that my question is slightly different, and the solution that was provided to the other question doesn't work anymore (however it could have worked in 2016). The crucial part of my question is how to achieve the goal without calling the QTest::qExec function multiple times.

0

There are 0 best solutions below