diff options
Diffstat (limited to 'docs/reference/testing.md')
| -rw-r--r-- | docs/reference/testing.md | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/docs/reference/testing.md b/docs/reference/testing.md index 17225a682f51..3ed521111787 100644 --- a/docs/reference/testing.md +++ b/docs/reference/testing.md @@ -3,7 +3,7 @@ <!--* toc_depth: 3 *--> This page lists the facilities provided by GoogleTest for writing test programs. -To use them, include the header `gtest/gtest.h`. +To use them, add `#include <gtest/gtest.h>`. ## Macros @@ -94,7 +94,8 @@ Instantiates the value-parameterized test suite *`TestSuiteName`* (defined with The argument *`InstantiationName`* is a unique name for the instantiation of the test suite, to distinguish between multiple instantiations. In test output, the instantiation name is added as a prefix to the test suite name -*`TestSuiteName`*. +*`TestSuiteName`*. If *`InstantiationName`* is empty +(`INSTANTIATE_TEST_SUITE_P(, ...)`), no prefix is added. The argument *`param_generator`* is one of the following GoogleTest-provided functions that generate the test parameters, all defined in the `::testing` @@ -139,6 +140,7 @@ See also ### TYPED_TEST_SUITE {#TYPED_TEST_SUITE} `TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`)` +`TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`,`*`NameGenerator`*`)` Defines a typed test suite based on the test fixture *`TestFixtureName`*. The test suite name is *`TestFixtureName`*. @@ -168,6 +170,22 @@ TYPED_TEST_SUITE(MyFixture, MyTypes); The type alias (`using` or `typedef`) is necessary for the `TYPED_TEST_SUITE` macro to parse correctly. +The optional third argument *`NameGenerator`* allows specifying a class that +exposes a templated static function `GetName(int)`. For example: + +```cpp +class NameGenerator { + public: + template <typename T> + static std::string GetName(int) { + if constexpr (std::is_same_v<T, char>) return "char"; + if constexpr (std::is_same_v<T, int>) return "int"; + if constexpr (std::is_same_v<T, unsigned int>) return "unsignedInt"; + } +}; +TYPED_TEST_SUITE(MyFixture, MyTypes, NameGenerator); +``` + See also [`TYPED_TEST`](#TYPED_TEST) and [Typed Tests](../advanced.md#typed-tests) for more information. @@ -277,7 +295,8 @@ must be registered with The argument *`InstantiationName`* is a unique name for the instantiation of the test suite, to distinguish between multiple instantiations. In test output, the instantiation name is added as a prefix to the test suite name -*`TestSuiteName`*. +*`TestSuiteName`*. If *`InstantiationName`* is empty +(`INSTANTIATE_TYPED_TEST_SUITE_P(, ...)`), no prefix is added. The argument *`Types`* is a [`Types`](#Types) object representing the list of types to run the tests on, for example: @@ -1317,7 +1336,9 @@ tests. Initializes GoogleTest. This must be called before calling [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS). In particular, it parses the command line for the flags that GoogleTest recognizes. Whenever a GoogleTest flag is seen, it -is removed from `argv`, and `*argc` is decremented. +is removed from `argv`, and `*argc` is decremented. Keep in mind that `argv` +must terminate with a `NULL` pointer (i.e. `argv[argc]` is `NULL`), which is +already the case with the default `argv` passed to `main`. No value is returned. Instead, the GoogleTest flag variables are updated. |
