Search code examples
unit-testinggoogletest

UnitTest with gtest, can we create an object in the main that would be accessible in every test?


We are trying to make a UnitTest using gtest. However, in our tests we create an objet from a particular class we included. The issue is that we have to give value to the constructor, so each time we run our UnitTest program the user have to write the values to construct the object for each test since we create a new object in each tests. We are making a lot's of test, thus it is getting very unpractical.

Is there a method we could make to create one object that could be used in each test?

Thank you!

(Yes, we are beginner: it is our first time programming a big program and using gtest).


Solution

  • You can use a Fixture class. It is described in the documentation.