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?
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 .
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.
You can get a test name using TestInfo class:
::testing::UnitTest::GetInstance()->current_test_info()->name()
You can find more details here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With