Googletest export

Update advanced.md

PiperOrigin-RevId: 364839958
This commit is contained in:
Abseil Team 2021-03-24 10:49:12 -07:00 committed by Dino Radaković
parent 4595745f72
commit 5142ccd2d4

View File

@ -813,7 +813,8 @@ initialized from the command-line flag `--gtest_death_test_style`).
consideration to be run - much like the `threadsafe` mode on POSIX.
Other values for the variable are illegal and will cause the death test to fail.
Currently, the flag's default value is **"fast"**
Currently, the flag's default value is
**`"fast"`**.
1. the child's exit status satisfies the predicate, and
2. the child's stderr matches the regular expression.
@ -1374,7 +1375,7 @@ The following statement will instantiate tests from the `FooTest` test suite
each with parameter values `"meeny"`, `"miny"`, and `"moe"`.
```c++
INSTANTIATE_TEST_SUITE_P(InstantiationName,
INSTANTIATE_TEST_SUITE_P(MeenyMinyMoe,
FooTest,
testing::Values("meeny", "miny", "moe"));
```
@ -1383,51 +1384,54 @@ INSTANTIATE_TEST_SUITE_P(InstantiationName,
NOTE: The code above must be placed at global or namespace scope, not at
function scope.
Per default, every `TEST_P` without a corresponding `INSTANTIATE_TEST_SUITE_P`
causes a failing test in test suite `GoogleTestVerification`. If you have a test
suite where that omission is not an error, for example it is in a library that
may be linked in for other reason or where the list of test cases is dynamic and
may be empty, then this check can be suppressed by tagging the test suite:
The first argument to `INSTANTIATE_TEST_SUITE_P` is a unique name for the
instantiation of the test suite. The next argument is the name of the test
pattern, and the last is the parameter generator.
```c++
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FooTest);
```
You can instantiate a test pattern more than once, so to distinguish different
instances of the pattern, the instantiation name is added as a prefix to the
actual test suite name. Remember to pick unique prefixes for different
instantiations. The tests from the instantiation above will have these names:
To distinguish different instances of the pattern (yes, you can instantiate it
more than once), the first argument to `INSTANTIATE_TEST_SUITE_P` is a prefix
that will be added to the actual test suite name. Remember to pick unique
prefixes for different instantiations. The tests from the instantiation above
will have these names:
* `InstantiationName/FooTest.DoesBlah/0` for `"meeny"`
* `InstantiationName/FooTest.DoesBlah/1` for `"miny"`
* `InstantiationName/FooTest.DoesBlah/2` for `"moe"`
* `InstantiationName/FooTest.HasBlahBlah/0` for `"meeny"`
* `InstantiationName/FooTest.HasBlahBlah/1` for `"miny"`
* `InstantiationName/FooTest.HasBlahBlah/2` for `"moe"`
* `MeenyMinyMoe/FooTest.DoesBlah/0` for `"meeny"`
* `MeenyMinyMoe/FooTest.DoesBlah/1` for `"miny"`
* `MeenyMinyMoe/FooTest.DoesBlah/2` for `"moe"`
* `MeenyMinyMoe/FooTest.HasBlahBlah/0` for `"meeny"`
* `MeenyMinyMoe/FooTest.HasBlahBlah/1` for `"miny"`
* `MeenyMinyMoe/FooTest.HasBlahBlah/2` for `"moe"`
You can use these names in [`--gtest_filter`](#running-a-subset-of-the-tests).
This statement will instantiate all tests from `FooTest` again, each with
parameter values `"cat"` and `"dog"`:
The following statement will instantiate all tests from `FooTest` again, each
with parameter values `"cat"` and `"dog"`:
```c++
const char* pets[] = {"cat", "dog"};
INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest,
testing::ValuesIn(pets));
INSTANTIATE_TEST_SUITE_P(Pets, FooTest, testing::ValuesIn(pets));
```
The tests from the instantiation above will have these names:
* `AnotherInstantiationName/FooTest.DoesBlah/0` for `"cat"`
* `AnotherInstantiationName/FooTest.DoesBlah/1` for `"dog"`
* `AnotherInstantiationName/FooTest.HasBlahBlah/0` for `"cat"`
* `AnotherInstantiationName/FooTest.HasBlahBlah/1` for `"dog"`
* `Pets/FooTest.DoesBlah/0` for `"cat"`
* `Pets/FooTest.DoesBlah/1` for `"dog"`
* `Pets/FooTest.HasBlahBlah/0` for `"cat"`
* `Pets/FooTest.HasBlahBlah/1` for `"dog"`
Please note that `INSTANTIATE_TEST_SUITE_P` will instantiate *all* tests in the
given test suite, whether their definitions come before or *after* the
`INSTANTIATE_TEST_SUITE_P` statement.
Additionally, by default, every `TEST_P` without a corresponding
`INSTANTIATE_TEST_SUITE_P` causes a failing test in test suite
`GoogleTestVerification`. If you have a test suite where that omission is not an
error, for example it is in a library that may be linked in for other reasons or
where the list of test cases is dynamic and may be empty, then this check can be
suppressed by tagging the test suite:
```c++
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FooTest);
```
You can see [sample7_unittest.cc] and [sample8_unittest.cc] for more examples.
[sample7_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample7_unittest.cc "Parameterized Test example"