Google test: 可以查询测试治具名称吗?
Google test: Can I query the name of the test fixture?
我想使用 google 测试编写一个 class,它派生自 ::testing::Test 并主要使用构造函数或 SetUp 和 TearDown() 向其添加功能。看起来 SetUp/TearDown 是到目前为止的方法。我的问题是:
假设我们有一个像这样的小测试夹具:
TEST_F (PerformanceTest, Inputs)
{
EXPECT_EQ (0.0, performSaxpy(10, 4.0F, 3.0F, 2.0F));
EXPECT_EQ (0.0, performSaxpy(1, 5.0F, 4.0F, 3.0F));
EXPECT_EQ (0.0, performSaxpy(10, 12.0F, 2.0F, 1.0F));
}
我想要做的是,当 SetUp() 函数被调用时,我希望其中的代码查询测试夹具的名称 class (PerformanceTest),以及测试对象的名称(输入)。
为什么我需要这样做?因为我想将测试夹具的结果写入 xml 文件。由于各种原因,我无法使用 google 测试已经提供的默认 XML 输出格式。但是,在 google 测试的默认 XML 输出中,我们得到了测试夹具 class 和测试对象的名称,所以希望我们可以通过自定义来实现...这可能吗?
您可以使用 TestInfo 获取测试名称 class:
::testing::UnitTest::GetInstance()->current_test_info()->name()
您可以找到更多详细信息here
我想使用 google 测试编写一个 class,它派生自 ::testing::Test 并主要使用构造函数或 SetUp 和 TearDown() 向其添加功能。看起来 SetUp/TearDown 是到目前为止的方法。我的问题是:
假设我们有一个像这样的小测试夹具:
TEST_F (PerformanceTest, Inputs)
{
EXPECT_EQ (0.0, performSaxpy(10, 4.0F, 3.0F, 2.0F));
EXPECT_EQ (0.0, performSaxpy(1, 5.0F, 4.0F, 3.0F));
EXPECT_EQ (0.0, performSaxpy(10, 12.0F, 2.0F, 1.0F));
}
我想要做的是,当 SetUp() 函数被调用时,我希望其中的代码查询测试夹具的名称 class (PerformanceTest),以及测试对象的名称(输入)。
为什么我需要这样做?因为我想将测试夹具的结果写入 xml 文件。由于各种原因,我无法使用 google 测试已经提供的默认 XML 输出格式。但是,在 google 测试的默认 XML 输出中,我们得到了测试夹具 class 和测试对象的名称,所以希望我们可以通过自定义来实现...这可能吗?
您可以使用 TestInfo 获取测试名称 class:
::testing::UnitTest::GetInstance()->current_test_info()->name()
您可以找到更多详细信息here