创建常规TEST
(或TEST_F
)时,我可以访问存储在中的测试用例信息test_info_
,例如:
TEST_F(MyTestSuite, TestCaseOne)
{
// ...
test_info_->name(); // will return "TestCaseOne"
}
当我使用参数化(TEST_P
)变体时,我想访问此类信息,该变体允许我定义基于夹具的测试。
从内幕看,我发现它的TEST_P
工作原理与她的表亲TEST
和完全不同TEST_F
,因为它通过调用方法注册了新的测试用例::testing::UnitTest::GetInstance()->parameterized_test_registry().GetTestCasePatternHolder<test_case_name>(#test_case_name, __FILE__, __LINE__)->AddTestPattern(...)
。我知道,继承自该类的类TestWithParam
将运行所有已注册TEST_P
的测试用例。
有没有一种方法(运行时或编译时)访问a的名称(字符串)TEST_P
?
TestInfo
实例实际上有一个吸气剂。从文档中:
为了获得
TestInfo
当前运行的测试,调用对象current_test_info()
上的UnitTest
单个对象:// 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());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句