创建 Qt Test
Qt Creator 集成了 Qt Test框架,用于对 Qt 应用程序和库进行单元测试。
创建 Qt 测试:
- 转到File >New Project >Test Project 。
- 选择 Qt Test Project>Choose 。
- 在Project and Test Information 对话框中,指定项目和测试的设置。
- 在Test case name 中,输入测试用例的名称。
- 选择Requires QApplication ,将QApplication 的 include 语句添加到项目的 main.cpp 文件中。
- 选择GUI Application ,创建 Qt XML 应用程序。
- 选择Generate initialization and cleanup code ,向测试中添加测试框架执行的函数,以初始化和清理测试。
- 在Build system 中,选择用于构建项目的构建系统:CMake、qmake 或 Qbs。使用 Qt 5 或 Qt 6.4 或更早版本开发时,要使用 CMake 构建,请选择CMake for Qt 5 and Qt 6 。
Qt Creator 在指定的项目目录中创建测试。编辑 .cpp 文件,为测试中的每个测试函数添加私有槽。
有关创建 Qt 测试的更多信息,请参阅创建测试。
Copyright © The Qt Company Ltd. and other contributors. 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.