更改谷歌测试框架默认打印模式

时间:2016-08-25 05:32:15

标签: c++11 googletest

Google测试框架默认打印

 [==========] Running 4 tests from 1 test case.   
 [----------] Global test environment set-up.   
 [----------] 4 tests from gcc_tests   
 [ RUN      ]gcc_tests.functionality_test  
 [       OK ] gcc_tests.functionality_test (0 ms)    
 [ RUN      ] gcc_tests.functionality_test_1    
 [       OK ] gcc_tests.functionality_test_2 (0 ms)     
 [ RUN      ] gcc_tests.functionality_test_3    
 [       OK ] gcc_tests.functionality_test_3 (0 ms)    
 [ RUN      ] gcc_tests.functionality_test_4    
 [       OK ] gcc_tests.functionality_test_4(471 ms)   
 [----------] 4 tests from gcc_tests (471 ms total)  

 [----------] Global test environment tear-down   
 [==========] 4 tests from 1 test case ran. (471 ms total)    
 [  PASSED  ] 4 tests.   

如何在支架内用秒替换毫秒,如上图所示。

如果时间超过60秒,那么应该用分钟替换 例如,如支架471毫秒所示,它应该用0.475秒替换,如果时间是76秒 它应该用1分16秒代替。

1 个答案:

答案 0 :(得分:3)

我可以想出两种方法来实现理想的行为:

  1. 使用event listener API自定义输出。
  2.   

    Google Test提供了一个事件监听器API,可让您收到有关测试程序进度和测试失败的通知。您可以收听的事件包括测试程序的开始和结束,测试用例或测试方法等。您可以使用此API来扩充或替换标准控制台输出,替换XML输出,或提供完全不同的输出形式,例如GUI或数据库。例如,您还可以使用测试事件作为检查点来实现资源泄漏检查程序。

    1. 使用XML输出,以便稍后对结果进行后期处理,并根据您的意愿格式化时间值。