Ctest - 使用--test-command选项进行构建和测试

时间:2016-07-06 21:13:14

标签: unit-testing cmake googletest ctest

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

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

1 个答案:

答案 0 :(得分: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 目录使用..,对于{em> { binary 目录):

.

从CMake 3.17开始,您现在可以在定义测试本身的CMake文件中指定要传递给CTest的参数(以及各个测试的参数)。 ctest --build-and-test .. . --build-generator "Visual Studio 16 2019" --test-command Test1 --gtest_output=xml 变量采用以分号分隔的参数列表,以传递给CTest。因此,坚持以上示例,您可以执行以下操作:

CMAKE_CTEST_ARGUMENTS