From dda72ef32181edbfcd32a8c52b4740cd8061ab6f Mon Sep 17 00:00:00 2001 From: kaswhy Date: Fri, 29 Dec 2023 02:05:18 +0900 Subject: [PATCH 1/3] Docs: add conditions for calling TearDown() --- docs/advanced.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index 0e1f812b..8e1df2a8 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -1006,9 +1006,12 @@ Environment* AddGlobalTestEnvironment(Environment* env); 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. +reported fatal failures and `GTEST_SKIP()` was not called. + +RUN_ALL_TESTS() calls TearDown() for each environment object when they are recreated +for each iteration. However, if the test environments are not recreated for each iteration, +TearDown() is called only on the last iteration. +Additionally, TearDown() is executed regardless of whether the tests were run or not. It's OK to register multiple environment objects. In this suite, their `SetUp()` will be called in the order they are registered, and their `TearDown()` will be From 778badf63a6459b15c237ffad798ef9a484e84fe Mon Sep 17 00:00:00 2001 From: kaswhy Date: Fri, 12 Jan 2024 01:06:00 +0900 Subject: [PATCH 2/3] Docs: add conditions for calling SetUp and TearDown() --- docs/advanced.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index 8e1df2a8..ff50edab 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -1004,14 +1004,18 @@ calling the `::testing::AddGlobalTestEnvironment()` function: Environment* AddGlobalTestEnvironment(Environment* env); ``` -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. +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. -RUN_ALL_TESTS() calls TearDown() for each environment object when they are recreated -for each iteration. However, if the test environments are not recreated for each iteration, -TearDown() is called only on the last iteration. -Additionally, TearDown() is executed regardless of whether the tests were run or not. +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. It's OK to register multiple environment objects. In this suite, their `SetUp()` will be called in the order they are registered, and their `TearDown()` will be From 1cab76c7b80756c42008fc36870146c8e38507de Mon Sep 17 00:00:00 2001 From: kaswhy Date: Tue, 23 Jan 2024 21:39:40 +0900 Subject: [PATCH 3/3] Docs: Add mention of `gtest_recreate_environments_when_repeating` --- docs/advanced.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index ff50edab..715bd047 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -1004,18 +1004,20 @@ calling the `::testing::AddGlobalTestEnvironment()` function: Environment* AddGlobalTestEnvironment(Environment* env); ``` -Now, when RUN_ALL_TESTS() is invoked, it first calls the SetUp() method. +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. +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). +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 is not +run due to a fatal failure or `GTEST_SKIP()`. -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. +Calling `SetUp()` and `TearDown()` for each iteration depends on the +`gtest_recreate_environments_when_repeating variable`. `SetUp()` and `TearDown()` +are 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. It's OK to register multiple environment objects. In this suite, their `SetUp()` will be called in the order they are registered, and their `TearDown()` will be