Question

I would like to loop over test cases in googleTest. What i call a test case here is this kind of thing:

TEST_F(AppsTests, test_wkf1) 
{ 
    //...
}

If i loop inside the TEST_F, it crashes. So I would a loop on test cases, as in

foreach(QString s, list)
{
      TEST_F(AppsName, test_i)
      {
           //...
      }
}

I thought of this work around: i do a SetUp() and a TearDown() inside each loop of the loop. But for doing so, i have to start the test case with TearDown() and end it with setUp(). which is not nice.

Is there another way, for instance defining an environment above the fixture ?

Was it helpful?

Solution

You could use value-parameterized tests. Basically, you'd do something like the following:

class AppsTests : public ::testing::TestWithParam<QString>
{
    // ...
};

TEST_P(AppsTests, TestA) { /* ... */ }
TEST_P(AppsTests, TestB) { /* ... */ }

INSTANTIATE_TEST_CASE_P(MyTests, AppsTests, ::testing::ValuesIn(list));

After this, you'll generate a test for each value contained in list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top