Capitolo 6: Salto dei test con QSKIP
Utilizzo di QSKIP (description) in una funzione di test
Se la macro QSKIP() viene chiamata da una funzione di test, interrompe l'esecuzione del test senza aggiungere un errore al log dei test. Può essere utilizzata per saltare i test che sicuramente falliranno. Il testo nel parametro QSKIP description viene aggiunto al log dei test e dovrebbe spiegare perché il test non è stato eseguito.
QSKIP può essere utilizzato per saltare i test quando l’implementazione non è ancora completa o non è supportata su una determinata piattaforma. In presenza di errori noti, si consiglia di utilizzare QEXPECT_FAIL, poiché consente di eseguire il resto del test, quando possibile.
Esempio di utilizzo di QSKIP in una funzione di test:
if (tst_Databases::getMySqlVersion(db).section(QChar('.'), 0, 0).toInt() < 5)
QSKIP("Test requires MySQL >= 5.0");In un test basato sui dati, ogni chiamata a ` QSKIP()` salta solo la riga corrente dei dati di test. Se il test basato sui dati contiene una chiamata incondizionata a `QSKIP`, genera un messaggio di salto per ogni riga dei dati di test.
Utilizzo di QSKIP in una funzione _data
Se chiamata da una funzione _data, la macro QSKIP() interrompe l’esecuzione della funzione _data. Ciò impedisce l’esecuzione della funzione di test associata.
Di seguito è riportato un esempio:
QTest::addColumn<bool>("bool");
QTest::newRow("local.1") << false;
QTest::newRow("local.2") << true;
QSKIP("skipping all");Utilizzo di QSKIP da initTestCase() o initTestCase_data()
Se chiamata da initTestCase() o initTestCase_data(), la macro QSKIP() salterà tutte le funzioni di test e _data.
Vedi anche Selezione dei meccanismi appropriati per escludere i test.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.