本页内容

第 6 章:使用 QSKIP 跳过测试

在测试函数中使用 QSKIP(description )

如果在测试函数中调用QSKIP() 宏,它将停止测试的执行,且不会在测试日志中添加失败记录。该宏可用于跳过那些确定会失败的测试。QSKIP 参数description 中的文本将被追加到测试日志中,该文本应说明为何未执行该测试。

当实现尚未完成或在特定平台上不支持时,可以使用 QSKIP 跳过测试。当存在已知的失败情况时,建议使用QEXPECT_FAIL ,因为它在可能的情况下支持继续运行剩余的测试。

测试函数中 QSKIP 的示例:

if (tst_Databases::getMySqlVersion(db).section(QChar('.'), 0, 0).toInt() < 5)
    QSKIP("Test requires MySQL >= 5.0");

在数据驱动测试中,每次调用QSKIP() 仅会跳过当前一行测试数据。如果数据驱动测试中包含对 QSKIP 的无条件调用,则会针对每行测试数据生成一条跳过消息。

在 _data 函数中使用 QSKIP

如果从 _data 函数中调用,QSKIP() 宏将停止 _data 函数的执行。这将阻止相关测试函数的执行。

示例如下:

    QTest::addColumn<bool>("bool");
    QTest::newRow("local.1") << false;
    QTest::newRow("local.2") << true;

    QSKIP("skipping all");

在 initTestCase() 或 initTestCase_data() 中使用 QSKIP

若从initTestCase() 或initTestCase_data() 中调用,QSKIP()宏将跳过所有测试函数和_data函数。

另请参阅 《选择适当的机制来排除测试》。

© 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.