c++ - 如何将 Google 测试输出打印到文本文件?

标签 c++ c bash cmake googletest

我使用如下所示的代码启动并运行了 gtest。我想将测试输出打印到文本文件,而不是在控制台中显示。有办法做到这一点吗?

我从控制台使用 cmake 运行测试:cmake CMakeLists.txt && make && ./runTests

#include "cw-test.c"
#include <stdio.h>
#include <gtest/gtest.h>

TEST(InputValidationTest, ValidateEntryLine)
{
    ...
}

...

int main(int argc, char **argv) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

最佳答案

您可以将 runTests 命令的输出重定向到一个文件:

cmake CMakeLists.txt && make && ./runTests > test_output.txt

另请参阅 this这解释了为什么您不需要我在评论中使用的 & 。正如 Awaken 的回答所说, &stdoutstderr 重定向到同一个文件。但是由于 googletest 输出总是转到 stdout,您可以省略 &

关于c++ - 如何将 Google 测试输出打印到文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19736536/

相关文章:

c++ - 使用变量来确定结构成员

c - 以分号结尾的 while 循环

Bash:通过子文件夹集循环ffmpeg命令并将其定向到文件夹中的文件进行处理

c++ - 返回 std::tuple 并 move 语义/复制省略

c++ - 统一内存分配cuda的功能关键字

c - 为什么编译器显示意外结果?

bash - 如何用shell脚本删除空格?

linux - 定期将 bash 历史推送到 github

c++ - OpenGL,如何设置GLSL版本?

C 程序在不使用 string.h 库的情况下检索两个字符之间的文本