Status: In Progress
Priority: P3: Somewhat important
Affects Version/s: None
Fix Version/s: None
Component/s: Testing: qtestlib
I have a helper class from which my test case derives from. The helper class sets up a bunch of stuff via non-test helper functions. I was using QVERIFY, QCOMPARE, etc. in those helper functions, until I realised that the test function keeps executing.
In the docs, each test function has this note:
Note: This macro can only be used in a test function that is invoked by the test framework.
This all makes sense, but it leaves a huge gap in implementing and using helper functions in tests.
My current workaround is to duplicate some of the macros:
I store a failureMessage string in the helper class:
I ensure that the result of the helper is used (they return bool so that the actual test function can verify that they succeed), and I give them a goofy prefix so that it's obvious that they're a helper:
For example, the VERIFY macro returns false if it fails, and stores the failure message. The client code in the actual test functions uses the helper like so:
This has worked fine so far, but it uses private API, so it would be good if there was an official way to do this.
|For Gerrit Dashboard: QTBUG-66320|
|415580,8||Add QTEST_CHECKED() macro to support test helper functions||dev||qt/qtbase||Status: NEW||+1||0|
|248490,10||WIP: Add _THROW variants to testlib macros||dev||qt/qtbase||Status: ABANDONED||-2||0|
|258296,3||WIP: Make Qt Test macros throw on failure||dev||qt/qtbase||Status: ABANDONED||-2||0|
|303234,4||QQuickApplicationHelper: don't use QTest macros outside test functions||dev||qt/qtquickcontrols2||Status: MERGED||+2||0|
|304562,3||QQuickApplicationHelper: don't use QTest macros outside test functions||5.12||qt/qtquickcontrols2||Status: MERGED||+2||0|
|304563,3||QQuickApplicationHelper: don't use QTest macros outside test functions||5.15||qt/qtquickcontrols2||Status: MERGED||+2||0|