C++ 在Google测试参数化测试用例(`test\u P`)中访问测试信息

C++ 在Google测试参数化测试用例(`test\u P`)中访问测试信息,c++,unit-testing,googletest,googlemock,C++,Unit Testing,Googletest,Googlemock,当我创建常规测试或测试时,我可以访问存储在测试信息中的测试用例信息,如: 我希望在使用参数化TEST_p变量时访问此类信息,该变量允许我定义基于夹具的测试 从引擎盖下面看,我可以看到TEST_p的工作方式与她的堂兄TEST和TEST_F完全不同,因为它通过调用::testing::UnitTest::GetInstance->parameterized_TEST_registry.GetTestCasePatternHoldertest_case_name、\uuu文件、\uu行\uuuuuu-

当我创建常规测试或测试时,我可以访问存储在测试信息中的测试用例信息,如:

我希望在使用参数化TEST_p变量时访问此类信息,该变量允许我定义基于夹具的测试

从引擎盖下面看,我可以看到TEST_p的工作方式与她的堂兄TEST和TEST_F完全不同,因为它通过调用::testing::UnitTest::GetInstance->parameterized_TEST_registry.GetTestCasePatternHoldertest_case_name、\uuu文件、\uu行\uuuuuu->AddTestPattern来注册新的测试用例。。。方法我知道继承自TestWithParam的类将运行所有注册的测试用例


有没有一种方法可以在运行时或编译时访问测试的名称字符串?

TestInfo实例实际上有一个getter。发件人:

要为当前运行的测试获取TestInfo对象,请调用 UnitTest singleton对象的当前\u测试\u信息:

// Gets information about the currently running test.
// Do NOT delete the returned object - it's managed by the UnitTest class.
const ::testing::TestInfo* const test_info =
  ::testing::UnitTest::GetInstance()->current_test_info();
printf("We are in test %s of test case %s.\n",
       test_info->name(), test_info->test_case_name());

TestInfo实例实际上有一个getter。发件人:

要为当前运行的测试获取TestInfo对象,请调用 UnitTest singleton对象的当前\u测试\u信息:

// Gets information about the currently running test.
// Do NOT delete the returned object - it's managed by the UnitTest class.
const ::testing::TestInfo* const test_info =
  ::testing::UnitTest::GetInstance()->current_test_info();
printf("We are in test %s of test case %s.\n",
       test_info->name(), test_info->test_case_name());