Reputation: 105
I'm running unit tests with gtest. However I'm also using google glog in the code I'm testing. Unfortunately this output gets in the way of the test results and looks messy. How do I do I get rid of the glog output?
Upvotes: 3
Views: 3116
Reputation: 618
This seems to work, suppressing all log messages.
int main(int argc, char * argv[]) {
FLAGS_logtostderr = true;
FLAGS_minloglevel = 5;
google::InitGoogleLogging(argv[0]);
// Start running unit tests here
}
Upvotes: 3
Reputation: 3706
From the Advanced Guide, define your own empty EventListener and surpass all debug log and then remove the default printer from the event listener.
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();
}
Sample program here
Upvotes: 1