创建 Boost 测试

要构建和运行 Boost 测试,请在计算机上安装 Boost.Test。通常,Boost 安装包中已包含该组件。请从Boost.org 下载 Boost。

如果编译器和构建系统能够找到 Boost 库,则在创建测试时无需指定包含目录。

要创建 Boost 测试:

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

    Boost 测试项目向导中的“项目和测试信息”对话框

    1. 在“Test framework ”中,选择“Boost Test (header only) ”以包含所需的头文件,或选择“Boost Test (shared libraries) ”以链接到 Boost Test。
    2. 在“Test suite name ”中,输入测试套件的名称。
    3. Test case name 中,输入测试用例的名称。
    4. 在“Boost include directory (optional) ”中,输入包含 Boost.Test 所需文件的目录路径,例如version.hpp 以及包含测试头文件的test 子文件夹。
    5. 在“Build system ”中,选择用于构建项目的构建系统:CMake、qmake 或 Qbs。

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

有关创建 Boost 测试的更多信息,请参阅Boost.Test

注意:在 扫描测试时, 解析器只考虑直接或间接包含 Boost 测试库头文件之一的文件(任何以boost/test/ 开头且带有.hpp 后缀的 include 语句)。当前不会被构建的文件将被忽略。

另请参阅 《操作指南:测试》《选择构建系统》和《测试》。

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.