[Development] Supporting helper functions in auto tests by providing throwing Qt Test macros

Edward Welbourne edward.welbourne at qt.io
Thu Apr 4 11:15:25 CEST 2019

Mitch Curtis (4 April 2019 11:01)
> The nice thing about the exception solution is that users can decide
> whether they want to wrap all helper calls in QCHECK_EXCEPTION to get
> complete stack traces for failures, or if they don't want to use it at
> all, resulting in neater code but slightly more difficult traces.

Indeed.  Then again, the nice thing about a currentTestFailed() way of
doing this is that, when a helper *does* want to execute the code after
the sub-helper, even if the sub-helper failed, it just needs to not
check for failure after the sub-helper; where an exception-based
solution requires that each layer of helper be well-behaved about using
RAII for the things that need tidy-up after a potentially-failing
sub-helper.  Which is, of course, A Good Thing, that I wish all tests
did, but I note that existing tests not infrequently leak stuff on
failure for want of exactly this discipline.

> If they didn't use QCHECK_EXCEPTION at all (and we made sure we caught
> exceptions correctly in the test runner), they'd get output like this:
>   FAIL!  : tst_App::openClose(ImageType) 'animationPanel->isVisible()' returned FALSE. ()
>      Loc: [/home/mitch/dev/slate/tests/shared/testhelper.cpp(1990)]

Indeed, and that's likely good enough in most cases.  When it isn't,
whoever's investigating the failure can just apply the macro at
whichever intervening layers whey wish had been reported.  The same, of
course, could also be applied to a currentTestFailed()-based macro,
albeit with the tiresome limitation of helpers needing to return void.


More information about the Development mailing list