创建 Catch2 测试
要构建和运行 Catch2 测试,您可以安装 Catch2 库和头文件,或者使用 Catch2 存储库中的单个头文件。
如果编译器和构建系统能够自动找到 Catch2 头文件,则在创建测试时无需指定包含目录。
要创建一个基本的 Catch2 测试:
- 转到“File ” > “New Project ” > “Test Project ”。
- 选择“Catch2 Test Project ” > “Choose ”,以创建包含 Catch2 测试模板代码的项目。
- 在“Project and Test Information ”对话框中,指定项目和测试的设置:

- 在“Test framework ”中,选择“Catch2 v3 (shared libraries) ”以链接到 Catch2(推荐用于第 3 版),或选择“Catch2 v2 (header only) ”以使用单个头文件(推荐用于第 2 版)。
- 在“Test case name ”中,为测试用例文件指定一个名称。
- 在“Catch2 install directory (optional) ”中,您可以输入包含 Catch2 头文件的目录路径。
- 选择“Use own main ”以使用自定义的主函数。
- 选择“Use Qt libraries ”以将项目配置为使用 Qt 功能。
- 在“Build system ”中,选择用于构建项目的构建系统:CMake、qmake 或 Qbs。
Qt Creator 在项目目录中创建测试。
有关创建 Catch2 测试的更多信息,请参阅Catch2。
注意:在扫描测试时 ,解析器仅考虑直接或间接包含某个常见 Catch2 头文件(catch2.hpp 、catch_all.hpp 等)的文件。当前不会被构建的文件将被忽略。
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.