The Qt Test module provides classes for unit testing Qt applications and libraries. All public methods are in the QTest 名称空间。此外, QSignalSpy 类提供对 Qt 的信号和槽的轻松自省,而 QAbstractItemModelTester 允许非破坏性测试项模型。
注意: Qt Test 模块没有二进制兼容性保证。这意味着使用 Qt Test 的应用程序只保证与开发时所针对的 Qt 版本一起时才能工作。不管怎样,源代码的兼容性是有保证的。
Using a Qt module's C++ API requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake .
使用
find_package()
command to locate the needed module component in the
Qt6
包:
find_package(Qt6 REQUIRED COMPONENTS Test)
target_link_libraries(mytarget PRIVATE Qt6::Test)
更多细节,见 构建采用 CMake 概述。
To configure the module for building with qmake, add the module as a value of the
QT
variable in the project's .pro file:
QT += testlib
The Qt Quick Test module enables unit testing of Qt Quick applications.
Qt Test 的变化 lists important changes in the module API and functionality that were done for the Qt 6 series of Qt.
Qt Test 模块在商业许可下是可用的来自 Qt 公司 . In addition, it is available under free software licenses: The GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。
Furthermore, Qt Test in Qt 6.5.1 may contain third party modules under the following permissive licenses:
| Catch2, version 2.13.10 | Boost 软件许可 1.0 |
| Cycle | MIT 许可 |
| Linux 性能事件第 3.7 版 | GNU GPL (一般公共许可) 第 2.0 版仅采用 Linux Syscall 注意 |
| Valgrind, version 3.20.0 | BSD 4 条款原始或旧的许可 |