如何将谷歌测试输出打印到文本文件
How to print Google Test output to a text file?
我已经使用如下所示的代码启动并运行了 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
另外,请参阅此内容,其中解释了为什么您不需要我在评论中使用的&
。正如 Awaken 的回答所说,&
将stdout
和stderr
重定向到同一个文件。但是由于googletest
输出总是转到stdout
因此您可以省略&
。
crayzeewulf的评论适用于任何Unix程序。"&>"的意思是将"stdout"和"stderr"中的输出重定向到您指定的其他位置。
更多信息可以在这里找到。http://www.mathinfo.u-picardie.fr/asch/f/MeCS/courseware/users/help/general/unix/redirection.html
相关文章:
- 如何使代码打印文本文件中的第一行?
- 我想使用 "cout" 命令慢慢打印文本,但我真的找不到任何解决方案
- C++ 在带有回车符的终端中重新打印文本
- 打印文本导致内存泄漏
- 如何使用递归打印文本反驳
- 从 HDFS 读取和打印文本文件
- 在 C++ 中打印文本文件时出现问题
- WinAPI - 如何打印文本以编辑控件
- 打印文本文件c++的输出
- c 打印文本以for循环
- 在 dlib 窗口中打印文本
- 使用GLUT简单地打印文本
- Cout 不会打印文本而没有 endl 在循环中?
- 为什么它只打印文本文件的一个单词,而不是将整个文本文件打印到html文件中
- 在Windows C++中打印文本和变量
- 无法从文件打印文本
- Libharu pdf创建:如何知道打印文本的大小
- opengl在屏幕菜单上打印文本变量
- 在指针之间打印文本
- 如何在按下回车键后使用cout打印文本