google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.52k stars 10.09k forks source link

Docs: add conditions for calling SetUp() and TearDown() #4435

Closed kaswhy closed 8 months ago

kaswhy commented 9 months ago

https://github.com/google/googletest/issues/3840#issue-1236510294

In the implementation, TearDown() is executed for each environment object when they are recreated for each iteration. If they are not recreated, it is only called on the last iteration.

before change (docs)

Now, when RUN_ALL_TESTS() is called, it first calls the SetUp() method of each environment object, then runs the tests if none of the environments reported fatal failures and GTEST_SKIP() was not called. RUN_ALL_TESTS() always calls TearDown() with each environment object, regardless of whether or not the tests were run.

after change (docs)

Now, when RUN_ALL_TESTS() is invoked, it first calls the SetUp() method. The tests are then executed, provided that none of the environments have reported fatal failures and GTEST_SKIP() has not been invoked. Finally, TearDown() is called.

Note that SetUp() and TearDown() are only invoked if there is at least one test to be performed. Importantly, TearDown() is executed even if the test itself is not run due to exception handling (e.g., fatal failures or if GTEST_SKIP() is invoked).

SetUp() and TearDown() are also called for each environment object when they are recreated for each iteration. However, if the test environments are not recreated for each iteration, SetUp() is called only on the first iteration, and TearDown() is called only on the last iteration.

google-cla[bot] commented 9 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.