Skip to content

Conversation

@kaswhy
Copy link
Contributor

@kaswhy kaswhy commented Dec 28, 2023

#3840 (comment)

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
Copy link

google-cla bot commented Dec 28, 2023

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.

@kaswhy kaswhy changed the title Docs: add conditions for calling TearDown() Docs: add conditions for calling SetUp() and TearDown() Jan 11, 2024
docs/advanced.md Outdated
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.
Now, when RUN_ALL_TESTS() is invoked, it first calls the SetUp() method.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the "of each environment object" part?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/google/googletest/blob/5126f7166109666a9c0534021fb1a3038659494c/googletest/src/gtest.cc#L5848C5-L5855C1

I think including that part might make it confusing. The comments in the code linked above correspond to the 'of each environment object' part.

docs/advanced.md Outdated
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).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of "exception handling", can we more accurately say if "the test is not run due to a fatal failure or GTEST_SKIP()"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make that change!

docs/advanced.md Outdated
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a link or at least mention gtest_recreate_environments_when_repeating?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll add a link.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.. I noticed that the Testing Reference doesn't include gtest_recreate_environments_when_repeating, so I just decided to mention it.

@copybara-service copybara-service bot merged commit fc0076f into google:main Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants