2

I have a gtest parameterized class that I would like to call some SetUp and TearDown in between each parameter. I know googletest offers SetUp which is before each test case and SetUpTestCase which is before ALL test cases.

I have something like this:

class MyParameterizedTest: public TestWithParam<MyParams>
{
public:
   MyParameterizedTest() {}

   void SetUp()
   {
      //called before every test case
   }

   void TearDown()
   {
      //called after every test case
   }

   static void SetUpTestCase()
   {
      //called at the begining of framework and before all test cases
   }

   static void TearDownTestCase()
   {
      //called at the end of the framework and after all test cases
   }

   //Wishing for something like:
   // void SetUpParameter()
   {
      //called before start of parameter
   }
};

INSTANTIATE_TEST_CASE_P(RegistrationTest, InterfaceTest, ValuesIn(AllTheValues::GetAllMyParams()));

Any thoughts on a way make this work? Maybe a way to see when the last test case has been run for a particular parameter? Or will I have to instantiate a test case for every individual parameter?

cheddarhead52
  • 61
  • 1
  • 4
  • 1
    Are you sure your code *doesn't* work? Static functions are separate per class, not per class template. – Kerrek SB Apr 09 '15 at 20:08
  • And to clarify: You are talking about [type-parametrized tests](https://code.google.com/p/googletest/wiki/AdvancedGuide#Type-Parameterized_Tests). – Kerrek SB Apr 09 '15 at 20:11
  • Yes type-parametrized test. Good clarification. I am not sure how the underlying templating of the Test Class works, but I am sure that the static SetUpTestCase and TearDownTestCase are only called once for my full set of test cases – cheddarhead52 Apr 09 '15 at 21:03

1 Answers1

0

I think it is against good practices to create such a combination, because:

Possible solution: - create separated testcases. It works. Going against the framework is almost always a bad route. What if the framework change? It it possible that you will have to align all your tests...which is really wrong in a production code.

Community
  • 1
  • 1
CyberGuy
  • 2,783
  • 1
  • 21
  • 31