PDA

View Full Version : QtTest- how to conditionally include/skip tests?



TorAn
26th May 2017, 19:22
That's the question - how to conditionally include or skip the tests defined in the class slots? (other then moving them to be private members)?

Thanks

high_flyer
28th May 2017, 20:46
I would say the question should be clarified.
What do you mean by conditionally?
I know what you mean literally, but why would you want to have some tests not execute?
I am not saying there is no good reason for it, but depending on the reason the correct way of doing it may differ.
One way would be to have some tests in a different test suit and call that test suit only when you need it.
Another way might be to give the test suit arguments that can be used in the code to execute only some tests.
I probably could find some other way if I think further.
It really depends on your needs and inclinations.

wysota
1st June 2017, 22:56
First of all it should be stated whether the condition should be checked during compile or run time.

TorAn
3rd June 2017, 12:54
Sorry, it was not clear. During compile time. Currently I am just moving the test methods from slot specification to regular methods. Perhaps there is a better way.

wysota
4th June 2017, 17:44
#ifdef might be a good way but I think moc doesn't obey ifdefs unless you explicitly pass them to it via a commandline switch. What you can do though is put the #ifdef in body of the test and add/remove a QSKIP macro.

matthewfchiera
4th September 2017, 01:26
Yes, you can conditionally skip tests using the QSKIP macro. The following provides an example to skip the database test if there is no database connection:
http://doc.qt.io/qt-4.8/qtest.html#QSKIP