【问题标题】:CTest --build-and-test with --test-command optionCTest --build-and-test 和 --test-command 选项
【发布时间】:2016-11-09 02:04:59
【问题描述】:

我使用 Ctest 运行一堆我使用 add_test() 注册的谷歌测试。目前,这些测试不接受任何参数。但是,我想在运行ctest 时为它们提供所有参数(所有人通用,特别是--gtest_output=xml)。

我听说可以使用 --test-command 选项,但是,我发现我们需要使用 --test-command--build-and-test。有这种用法的例子吗?

【问题讨论】:

标签: unit-testing cmake googletest ctest


【解决方案1】:

ctest 参数的格式在 CTest documentation 中指定,如下所示:

ctest --build-and-test <path-to-source> <path-to-build>
      --build-generator <generator>
      [<options>...]
      [--build-options <opts>...]
      [--test-command <command> [<args>...]]

因此,例如在 Visual Studio 上,您可以从构建文件夹运行测试 Test1(使用 .. 用于 source 目录,. 用于 binary 目录):

ctest --build-and-test .. . --build-generator "Visual Studio 16 2019" --test-command Test1 --gtest_output=xml

从 CMake 3.17 开始,您现在可以在定义测试本身的 CMake 文件中指定要传递给 CTest 的参数(以及单个测试的参数)。 CMAKE_CTEST_ARGUMENTS 变量采用分号分隔的参数列表传递给 CTest。所以,坚持上面的例子,你可以这样做:

set(CMAKE_CTEST_ARGUMENTS "--build-and-test;${CMAKE_SOURCE_DIR};${CMAKE_BINARY_DIR};--build-generator;${CMAKE_GENERATOR};--test-command;Test1;--gtest_output=xml")

【讨论】:

    猜你喜欢
    • 2010-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多