2011-09-08 3 views
3

gtest로 단위 테스트를 실행 중입니다. 그러나 나는 또한 테스트 코드에서 구글 glog를 사용하고있다. 불행하게도이 결과물은 테스트 결과를 방해하고 더러워집니다. 어떻게하면 그루터기 출력을 없앨 수 있습니까?Google 로그에서 로깅하지 않고 gtests를 실행하는 방법은 무엇입니까?

+0

스택 오버플로에 오신 것을 환영합니다. 질문을 편집하여 완성 해 주시겠습니까? –

답변

2

이 모든 로그 메시지를 표시, 작동하는 것 같다.

int main(int argc, char * argv[]) { 
    FLAGS_logtostderr = true; 
    FLAGS_minloglevel = 5; 
    google::InitGoogleLogging(argv[0]); 
    // Start running unit tests here 
} 
+0

다음과 같이하는 것이 좋습니다. – lutzky

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

+1

이것은 _test_ 출력을 제거합니다. 문제는 _log_ 출력을 제거하는 것입니다. – lutzky

관련 문제