Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google test: Can I query the name of the test fixture?

I want to use google test to write a class that derives from ::testing::Test and adds functionalities to it using mostly the constructor, or SetUp and TearDown(). Looks like SetUp/TearDown is the way to go so far. My question is:

Let's say we have a small test fixture like this:

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)); } 

What I want to do is, when the SetUp() function is called, I want code inside that to query the name of the test fixture class (PerformanceTest), and the name of the test object (Inputs).

Why do I need to do this? Because I want to write the results of my test fixture to an xml file. For various reasons, I cannot use the default XML output format that google test already provides. However, in google test's default XML output, we get the names of the test fixture class and test object, so hopefully we can do it by custom... Is this possible?

like image 725
nirvanaswap Avatar asked Jun 30 '16 17:06

nirvanaswap


People also ask

What is test fixture in Google test?

If you find yourself writing two or more tests that operate on similar data, you can use a test fixture. This allows you to reuse the same configuration of objects for several different tests. To create a fixture: Derive a class from ::testing::Test .

How do I name a Google test?

Both arguments TestFixtureName and TestName must be valid C++ identifiers and must not contain underscores ( _ ). TestFixtureName must be the name of a test fixture class—see Test Fixtures. The statements within the test body can be any code under test.


1 Answers

You can get a test name using TestInfo class:

::testing::UnitTest::GetInstance()->current_test_info()->name() 

You can find more details here

like image 75
Pawel Avatar answered Nov 03 '22 19:11

Pawel