创建Qt Quick 测试
Qt Creator 集成了用于 应用程序的Qt Quick Qt Quick Test单元测试框架,您可以将测试用例编写成 JavaScript 函数。
要创建Qt Quick 测试,请
- 转到File >New Project >Test Project 。
- 选择 Qt Quick Test Project>Choose 。
- 在Project and Test Information 对话框中,指定项目和测试的设置。
- 在Test case name 中,输入测试用例的名称。
- 选择Generate setup code ,在运行任何 QML 测试之前执行 C++ 代码。测试框架将调用槽和可调用函数,如在QML 测试前执行 C++ 中所述。
- 选择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 文件,为测试中的每个测试函数添加私有插槽。
注意: 在扫描测试时,解析器只考虑直接或间接包含 QuickTest 或其等效QtQuickTest/quicktest.h
的文件。如果找到了,它会尝试检测创建Qt Quick 测试程序的语句,如果能找到,它就会解析相应的 QML 文件。如果不使用当前配置构建 C++ 部分,则不会自动扫描 QML 文件。
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.