Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google test - before class

I'm running google test.

I need something like Before class. I have the SetUp() and TearDown() functions, but they run before and after each test. Now I need something global - like ctor, that should run only one time when the class loaded.

like image 341
Rat Avatar asked Mar 07 '16 14:03

Rat


2 Answers

You can define static member functions void SetUpTestCase() and void TearDownTestCase() in each of your fixture classes, i.e. in each class derived from ::testing::Test.

That code will run only once for each fixture, before and after all test in the fixture are run.

Check the docs.

like image 106
Antonio Pérez Avatar answered Sep 21 '22 12:09

Antonio Pérez


Inherit from class ::testing::Environment and override methods SetUp and TearDown, these methods will contain code for your global setup and tear down. Then, in the main function of executable that runs you tests, call function ::testing::AddGlobalTestEnvironment() before calling RUN_ALL_TESTS(). For more information, check the documentation:

https://github.com/google/googletest/blob/master/docs/advanced.md#global-set-up-and-tear-down

like image 36
Marko Popovic Avatar answered Sep 21 '22 12:09

Marko Popovic