Creating class level xunit report files with QtTestLib

Working on my new project SynPlayer – an controller to the Synology AudioStation based on C++ and Qt – it becomes evident to set up a testing infrastructure. Keeping dependency small and simple the decision was to facilitate QtTestLib for testing purposes.
To control test parameters and enable result reporting you may set the environment variable TESTARGS, for example to write the tests to the file xunit-result.xml in XUnit XML format pass:

TESTARGS="-o xunit-result.xml,xunitxml"

Unfortunately running multiple test cases will cause overwriting the report file with the result for each test, ending up eventually having only the last result.

The test case invocation is done by one of those methods:

QTest::qExec(QObject *test, QStringList args)
QTest::qExec(QObject *test, int argc, char **argv)

whereas the command line arguments taken from the TESTARGS variable are passed right into the tests. Supervising the passed parameters let raise the idea of manipulating the output parameters right before the test execution, preferably append the name of the test to the result file name.

Every test (case) should be derived from the QObject class. Thanks to the QObjects infrastructure the concrete class name can be easily obtained from the QMetaObjects method className().

For the first try the code sticks to statically replacing all output options with one option enforcing the results to be stored in XUnit XML format in a file named like xunit-result-TestClassName.xml ending up in the following code:

which yields the result files xunit-result-LoginCommandTest.xml and xunit-result-RemotePlayerTest.xml.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

vier + elf =