Qt Test
Qt Test 模块为 Qt 应用程序和库的单元测试提供了类。所有公共方法都在QTest 命名空间中。此外,QSignalSpy 类为 Qt 的信号和槽提供了简便的自省功能,QAbstractItemModelTester 允许对项目模型进行非破坏性测试。
注意: Qt Test 模块没有二进制兼容性保证。这意味着使用Qt Test 的应用程序只能保证在其开发时所对应的 Qt 版本上运行。不过,源代码兼容性是有保证的。
使用模块
使用 Qt 模块的 C++ API 需要直接或通过其他依赖关系与模块库链接。有几种构建工具为此提供了专门支持,包括CMake和qmake。
使用 CMake 构建
使用find_package()
命令在Qt6
软件包中找到所需的模块组件:
find_package(Qt6 REQUIRED COMPONENTS Test) target_link_libraries(mytarget PRIVATE Qt6::Test)
更多详情,请参阅使用 CMake 构建概述。
使用 qmake 构建
要配置使用 qmake 构建的模块,请在项目的 .pro 文件中添加模块作为QT
变量的值:
QT += testlib
文章和指南
参考资料
该 Qt Quick Test模块可对Qt Quick 应用程序进行单元测试。
模块演变
Changes toQt Test列出了针对 Qt 6 系列 Qt 在模块 API 和功能方面所做的重要更改。
许可证和归属
Qt Test 在商业许可下,您可以从Qt 公司获得该模块。此外,它还可在自由软件许可证下使用:GNU Lesser General Public License 第 3 版或GNU General Public License 第 2 版。详情请参见Qt Licensing。
此外,Qt 6.9.0 中的Qt Test 可能包含以下许可协议下的第三方模块:
Boost 软件许可证 1.0 | |
MIT 许可 | |
GNU 通用公共许可证 v2.0(仅限 Linux 系统调用注释 | |
BSD 4 条款 "原始 "或 "旧 "许可证 |
© 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.