创建 Catch2 测试

要构建和运行 Catch2 测试,你可以安装 Catch2 库和头文件,或者使用 Catch2 资源库中的单个 include 头文件。

如果编译器和构建系统能自动找到 Catch2 头文件,那么创建测试时就无需指定 include 目录。

创建基本 Catch2 测试

  1. 转到File >New Project >Test Project
  2. 选择Catch2 Test Project >Choose ,创建一个包含 Catch2 测试模板代码的项目。
  3. Project and Test Information 对话框中,指定项目和测试的设置:

    Catch2 测试项目向导中的项目和测试信息对话框

    1. Test framework 中,选择Catch2 v3 (shared libraries) 链接 Catch2(建议用于版本 3),或Catch2 v2 (header only) 使用单个头包含(建议用于版本 2)。
    2. Test case name 中,指定测试用例文件的名称。
    3. Catch2 install directory (optional) 中,可以输入 Catch2 头文件所在目录的路径。
    4. 选择Use own main 以使用自定义的主函数。
    5. 选择Use Qt libraries 设置项目以使用 Qt XML 功能。
    6. Build system 中,选择用于构建项目的构建系统:CMake、qmake 或 Qbs。

Qt Creator 在项目目录中创建测试。

有关创建 Catch2 测试的更多信息,请参阅Catch2

注意: 在扫描测试时,解析器只考虑直接或间接包含一个常用 Catch2 头文件的文件(catch2.hppcatch_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.