On 4/2/19 5:14 PM, Mitch Curtis 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.

This is massively annoying, and also a reason for
   - either writing longish macros that should be functions instead
   - duplicated code in tests.

> 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/

To me this looks promising. I wonder if qtestlib could catch a dedicated 
QTestException instead to avoid the need of the QCHECK_EXCEPTION macro.


Cheers,

Joerg
_______________________________________________
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development

Reply via email to