Can I give better names to value-parameterized tests in gtest?

前提是你 提交于 2019-12-03 05:38:32

INSTANTIATE_TEST_CASE_P accepts an optional 4th argument which can be used for this purpose. See https://github.com/google/googletest/blob/master/googletest/include/gtest/gtest-param-test.h#L1409.

Two ways: (http://osdir.com/ml/googletestframework/2011-09/msg00005.html)

1) Patch the existing PrettyUnitTestPrinter to print test names; something like:

--- a/gtest-1.7.0/src/gtest.cc
+++ b/gtest-1.7.0/src/gtest.cc
@@ -2774,6 +2774,7 @@ void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) {
 void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
   ColoredPrintf(COLOR_GREEN,  "[ RUN      ] ");
   PrintTestName(test_info.test_case_name(), test_info.name());
+  PrintFullTestCommentIfPresent(test_info);
   printf("\n");
   fflush(stdout);
 }

2) Write a new TestListener to print test results however you like. (https://code.google.com/p/googletest/source/browse/trunk/samples/sample9_unittest.cc) GTest allows registering a new test listener (and un-registering the builtin default), allowing pretty flexible customization of test output. See the link for example code.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!