我正在使用gtest运行单元测试。但是我也在我正在测试的代码中使用google glog。不幸的是,这个输出妨碍了测试结果并且看起来很混乱。我如何摆脱glog输出?
答案 0 :(得分:2)
这似乎有效,可以抑制所有日志消息。
int main(int argc, char * argv[]) {
FLAGS_logtostderr = true;
FLAGS_minloglevel = 5;
google::InitGoogleLogging(argv[0]);
// Start running unit tests here
}
答案 1 :(得分:1)
从“高级指南”中,定义您自己的空EventListener并超越所有调试日志,然后从事件侦听器中删除默认打印机。
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
// Gets hold of the event listener list.
::testing::TestEventListeners& listeners =
::testing::UnitTest::GetInstance()->listeners();
// Removes the default console output listener from the list so it will
// not receive events from Google Test and won't print any output. Since
// this operation transfers ownership of the listener to the caller we
// have to delete it as well.
delete listeners.Release(listeners.default_result_printer());
// Adds a listener to the end. Google Test takes the ownership.
// Basically you can define an empty class MinimalistPrinter
// derived from EmptyTestEventListener
listeners.Append(new MinimalistPrinter);
return RUN_ALL_TESTS();
}
示例程序here