第 6 章 使用 QSKIP 跳过测试

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

如果在测试函数中调用QSKIP() 宏,它将停止测试的执行,而不会在测试日志中添加失败记录。它可用于跳过肯定会失败的测试。QSKIPdescription 参数中的文本将附加到测试日志中,并应解释测试未执行的原因。

当实现尚未完成或在特定平台上不支持时,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 函数。

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

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