What's your goal with the hierarchy? Remember when you're defining a test like:
TEST_F(TestTrig, sine_test)
this defines a test (sine_test) that contains some assertions. It's defined as an object (TestTrig) that can contain member functions, member variables, etc. You can use inheritance and define your own structure to reuse code like:
class TestMath : public ::testing::Test {
public:
// Some common methods
long calcSum(long A[], size_t len);
};
class TestTrig : public TestMath {
public:
// Trig-specific methods
float calcHypotenuse(float A, float B);
};
But remember from the gtest primer: "Note that different tests in the same test case have different test fixture objects, and Google Test always deletes a test fixture before it creates the next one. Google Test does not reuse the same test fixture for multiple tests. Any changes one test makes to the fixture do not affect other tests." For example if you had:
TEST_F(TestTrig, sine_test);
TEST_F(TestTrig, cosine_test);
then those two tests are defined as separate objects. So if you assign a member variable in sine_test, the value won't be there there during cosine_test because it's a separate object. From this perspective gtest has no hierarchy at all and each test stands completely alone. Only code and global state is shared between tests.
If your goal is simply to run a group of tests, you can achieve that by clever naming. For example if you defined some tests:
TEST_F(TestMath_TestTrig, sine_test);
TEST_F(TestMath_TestTrig, cosine_test);
TEST_F(TestMath_TestGeom, test_triangle);
then you could use filtering to run any subset of tests like:
gtest --gtest_filter=TestMath*
or
gtest --gtest_filter=TestMath_TestTrig*:TestMath_TestGeom*
there are a lot of options, so you'll have to pick one that works for you.
-joey