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

Christian Kandeler Christian.Kandeler at qt.io
Wed Apr 3 10:45:38 CEST 2019


On Tue, 2 Apr 2019 15:14:38 +0000
Mitch Curtis <mitch.curtis at qt.io> wrote:

> As described in https://bugreports.qt.io/browse/QTBUG-66320, currently Qt users are on their own if they want to call helper functions that can fail a test. The reason is documented:
> 
>     Note: This macro can only be used in a test function that is invoked by the test framework.
> 
> A common workaround for this is to make the helper function return a bool indicating success or failure, and pass in a QString reference which is set to the failure message (if any).
> 
> I don't know how many people reading this have written comprehensive auto tests for an application, but not having helper functions is just not an option if you want maintainable code.
> 
> I looked into this briefly during the last hackathon we had, and from what I found, throwing an exception was the best approach:
> 
> https://codereview.qt-project.org/#/c/248490/

+2 for the general idea. It would solve a problem that comes up again and again and always requires awful workarounds.


Christian



More information about the Development mailing list