128f6c2f2SEnji Cooper# Testing Reference 228f6c2f2SEnji Cooper 328f6c2f2SEnji Cooper<!--* toc_depth: 3 *--> 428f6c2f2SEnji Cooper 528f6c2f2SEnji CooperThis page lists the facilities provided by GoogleTest for writing test programs. 6*5ca8c28cSEnji CooperTo use them, add `#include <gtest/gtest.h>`. 728f6c2f2SEnji Cooper 828f6c2f2SEnji Cooper## Macros 928f6c2f2SEnji Cooper 1028f6c2f2SEnji CooperGoogleTest defines the following macros for writing tests. 1128f6c2f2SEnji Cooper 1228f6c2f2SEnji Cooper### TEST {#TEST} 1328f6c2f2SEnji Cooper 1428f6c2f2SEnji Cooper<pre> 1528f6c2f2SEnji CooperTEST(<em>TestSuiteName</em>, <em>TestName</em>) { 1628f6c2f2SEnji Cooper ... <em>statements</em> ... 1728f6c2f2SEnji Cooper} 1828f6c2f2SEnji Cooper</pre> 1928f6c2f2SEnji Cooper 2028f6c2f2SEnji CooperDefines an individual test named *`TestName`* in the test suite 2128f6c2f2SEnji Cooper*`TestSuiteName`*, consisting of the given statements. 2228f6c2f2SEnji Cooper 2328f6c2f2SEnji CooperBoth arguments *`TestSuiteName`* and *`TestName`* must be valid C++ identifiers 2428f6c2f2SEnji Cooperand must not contain underscores (`_`). Tests in different test suites can have 2528f6c2f2SEnji Cooperthe same individual name. 2628f6c2f2SEnji Cooper 2728f6c2f2SEnji CooperThe statements within the test body can be any code under test. 2828f6c2f2SEnji Cooper[Assertions](assertions.md) used within the test body determine the outcome of 2928f6c2f2SEnji Cooperthe test. 3028f6c2f2SEnji Cooper 3128f6c2f2SEnji Cooper### TEST_F {#TEST_F} 3228f6c2f2SEnji Cooper 3328f6c2f2SEnji Cooper<pre> 3428f6c2f2SEnji CooperTEST_F(<em>TestFixtureName</em>, <em>TestName</em>) { 3528f6c2f2SEnji Cooper ... <em>statements</em> ... 3628f6c2f2SEnji Cooper} 3728f6c2f2SEnji Cooper</pre> 3828f6c2f2SEnji Cooper 3928f6c2f2SEnji CooperDefines an individual test named *`TestName`* that uses the test fixture class 4028f6c2f2SEnji Cooper*`TestFixtureName`*. The test suite name is *`TestFixtureName`*. 4128f6c2f2SEnji Cooper 4228f6c2f2SEnji CooperBoth arguments *`TestFixtureName`* and *`TestName`* must be valid C++ 4328f6c2f2SEnji Cooperidentifiers and must not contain underscores (`_`). *`TestFixtureName`* must be 4428f6c2f2SEnji Cooperthe name of a test fixture class—see 4528f6c2f2SEnji Cooper[Test Fixtures](../primer.md#same-data-multiple-tests). 4628f6c2f2SEnji Cooper 4728f6c2f2SEnji CooperThe statements within the test body can be any code under test. 4828f6c2f2SEnji Cooper[Assertions](assertions.md) used within the test body determine the outcome of 4928f6c2f2SEnji Cooperthe test. 5028f6c2f2SEnji Cooper 5128f6c2f2SEnji Cooper### TEST_P {#TEST_P} 5228f6c2f2SEnji Cooper 5328f6c2f2SEnji Cooper<pre> 5428f6c2f2SEnji CooperTEST_P(<em>TestFixtureName</em>, <em>TestName</em>) { 5528f6c2f2SEnji Cooper ... <em>statements</em> ... 5628f6c2f2SEnji Cooper} 5728f6c2f2SEnji Cooper</pre> 5828f6c2f2SEnji Cooper 5928f6c2f2SEnji CooperDefines an individual value-parameterized test named *`TestName`* that uses the 6028f6c2f2SEnji Coopertest fixture class *`TestFixtureName`*. The test suite name is 6128f6c2f2SEnji Cooper*`TestFixtureName`*. 6228f6c2f2SEnji Cooper 6328f6c2f2SEnji CooperBoth arguments *`TestFixtureName`* and *`TestName`* must be valid C++ 6428f6c2f2SEnji Cooperidentifiers and must not contain underscores (`_`). *`TestFixtureName`* must be 6528f6c2f2SEnji Cooperthe name of a value-parameterized test fixture class—see 6628f6c2f2SEnji Cooper[Value-Parameterized Tests](../advanced.md#value-parameterized-tests). 6728f6c2f2SEnji Cooper 6828f6c2f2SEnji CooperThe statements within the test body can be any code under test. Within the test 6928f6c2f2SEnji Cooperbody, the test parameter can be accessed with the `GetParam()` function (see 7028f6c2f2SEnji Cooper[`WithParamInterface`](#WithParamInterface)). For example: 7128f6c2f2SEnji Cooper 7228f6c2f2SEnji Cooper```cpp 7328f6c2f2SEnji CooperTEST_P(MyTestSuite, DoesSomething) { 7428f6c2f2SEnji Cooper ... 7528f6c2f2SEnji Cooper EXPECT_TRUE(DoSomething(GetParam())); 7628f6c2f2SEnji Cooper ... 7728f6c2f2SEnji Cooper} 7828f6c2f2SEnji Cooper``` 7928f6c2f2SEnji Cooper 8028f6c2f2SEnji Cooper[Assertions](assertions.md) used within the test body determine the outcome of 8128f6c2f2SEnji Cooperthe test. 8228f6c2f2SEnji Cooper 8328f6c2f2SEnji CooperSee also [`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P). 8428f6c2f2SEnji Cooper 8528f6c2f2SEnji Cooper### INSTANTIATE_TEST_SUITE_P {#INSTANTIATE_TEST_SUITE_P} 8628f6c2f2SEnji Cooper 8728f6c2f2SEnji Cooper`INSTANTIATE_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`param_generator`*`)` 8828f6c2f2SEnji Cooper\ 8928f6c2f2SEnji Cooper`INSTANTIATE_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`param_generator`*`,`*`name_generator`*`)` 9028f6c2f2SEnji Cooper 9128f6c2f2SEnji CooperInstantiates the value-parameterized test suite *`TestSuiteName`* (defined with 9228f6c2f2SEnji Cooper[`TEST_P`](#TEST_P)). 9328f6c2f2SEnji Cooper 9428f6c2f2SEnji CooperThe argument *`InstantiationName`* is a unique name for the instantiation of the 9528f6c2f2SEnji Coopertest suite, to distinguish between multiple instantiations. In test output, the 9628f6c2f2SEnji Cooperinstantiation name is added as a prefix to the test suite name 97*5ca8c28cSEnji Cooper*`TestSuiteName`*. If *`InstantiationName`* is empty 98*5ca8c28cSEnji Cooper(`INSTANTIATE_TEST_SUITE_P(, ...)`), no prefix is added. 9928f6c2f2SEnji Cooper 10028f6c2f2SEnji CooperThe argument *`param_generator`* is one of the following GoogleTest-provided 10128f6c2f2SEnji Cooperfunctions that generate the test parameters, all defined in the `::testing` 10228f6c2f2SEnji Coopernamespace: 10328f6c2f2SEnji Cooper 10428f6c2f2SEnji Cooper<span id="param-generators"></span> 10528f6c2f2SEnji Cooper 10628f6c2f2SEnji Cooper| Parameter Generator | Behavior | 10728f6c2f2SEnji Cooper| ------------------- | ---------------------------------------------------- | 10828f6c2f2SEnji Cooper| `Range(begin, end [, step])` | Yields values `{begin, begin+step, begin+step+step, ...}`. The values do not include `end`. `step` defaults to 1. | 10928f6c2f2SEnji Cooper| `Values(v1, v2, ..., vN)` | Yields values `{v1, v2, ..., vN}`. | 11028f6c2f2SEnji Cooper| `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. | 11128f6c2f2SEnji Cooper| `Bool()` | Yields sequence `{false, true}`. | 11228f6c2f2SEnji Cooper| `Combine(g1, g2, ..., gN)` | Yields as `std::tuple` *n*-tuples all combinations (Cartesian product) of the values generated by the given *n* generators `g1`, `g2`, ..., `gN`. | 11328f6c2f2SEnji Cooper| `ConvertGenerator<T>(g)` | Yields values generated by generator `g`, `static_cast` to `T`. | 11428f6c2f2SEnji Cooper 11528f6c2f2SEnji CooperThe optional last argument *`name_generator`* is a function or functor that 11628f6c2f2SEnji Coopergenerates custom test name suffixes based on the test parameters. The function 11728f6c2f2SEnji Coopermust accept an argument of type 11828f6c2f2SEnji Cooper[`TestParamInfo<class ParamType>`](#TestParamInfo) and return a `std::string`. 11928f6c2f2SEnji CooperThe test name suffix can only contain alphanumeric characters and underscores. 12028f6c2f2SEnji CooperGoogleTest provides [`PrintToStringParamName`](#PrintToStringParamName), or a 12128f6c2f2SEnji Coopercustom function can be used for more control: 12228f6c2f2SEnji Cooper 12328f6c2f2SEnji Cooper```cpp 12428f6c2f2SEnji CooperINSTANTIATE_TEST_SUITE_P( 12528f6c2f2SEnji Cooper MyInstantiation, MyTestSuite, 12628f6c2f2SEnji Cooper testing::Values(...), 12728f6c2f2SEnji Cooper [](const testing::TestParamInfo<MyTestSuite::ParamType>& info) { 12828f6c2f2SEnji Cooper // Can use info.param here to generate the test suffix 12928f6c2f2SEnji Cooper std::string name = ... 13028f6c2f2SEnji Cooper return name; 13128f6c2f2SEnji Cooper }); 13228f6c2f2SEnji Cooper``` 13328f6c2f2SEnji Cooper 13428f6c2f2SEnji CooperFor more information, see 13528f6c2f2SEnji Cooper[Value-Parameterized Tests](../advanced.md#value-parameterized-tests). 13628f6c2f2SEnji Cooper 13728f6c2f2SEnji CooperSee also 13828f6c2f2SEnji Cooper[`GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST`](#GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST). 13928f6c2f2SEnji Cooper 14028f6c2f2SEnji Cooper### TYPED_TEST_SUITE {#TYPED_TEST_SUITE} 14128f6c2f2SEnji Cooper 14228f6c2f2SEnji Cooper`TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`)` 143*5ca8c28cSEnji Cooper`TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`,`*`NameGenerator`*`)` 14428f6c2f2SEnji Cooper 14528f6c2f2SEnji CooperDefines a typed test suite based on the test fixture *`TestFixtureName`*. The 14628f6c2f2SEnji Coopertest suite name is *`TestFixtureName`*. 14728f6c2f2SEnji Cooper 14828f6c2f2SEnji CooperThe argument *`TestFixtureName`* is a fixture class template, parameterized by a 14928f6c2f2SEnji Coopertype, for example: 15028f6c2f2SEnji Cooper 15128f6c2f2SEnji Cooper```cpp 15228f6c2f2SEnji Coopertemplate <typename T> 15328f6c2f2SEnji Cooperclass MyFixture : public testing::Test { 15428f6c2f2SEnji Cooper public: 15528f6c2f2SEnji Cooper ... 15628f6c2f2SEnji Cooper using List = std::list<T>; 15728f6c2f2SEnji Cooper static T shared_; 15828f6c2f2SEnji Cooper T value_; 15928f6c2f2SEnji Cooper}; 16028f6c2f2SEnji Cooper``` 16128f6c2f2SEnji Cooper 16228f6c2f2SEnji CooperThe argument *`Types`* is a [`Types`](#Types) object representing the list of 16328f6c2f2SEnji Coopertypes to run the tests on, for example: 16428f6c2f2SEnji Cooper 16528f6c2f2SEnji Cooper```cpp 16628f6c2f2SEnji Cooperusing MyTypes = ::testing::Types<char, int, unsigned int>; 16728f6c2f2SEnji CooperTYPED_TEST_SUITE(MyFixture, MyTypes); 16828f6c2f2SEnji Cooper``` 16928f6c2f2SEnji Cooper 17028f6c2f2SEnji CooperThe type alias (`using` or `typedef`) is necessary for the `TYPED_TEST_SUITE` 17128f6c2f2SEnji Coopermacro to parse correctly. 17228f6c2f2SEnji Cooper 173*5ca8c28cSEnji CooperThe optional third argument *`NameGenerator`* allows specifying a class that 174*5ca8c28cSEnji Cooperexposes a templated static function `GetName(int)`. For example: 175*5ca8c28cSEnji Cooper 176*5ca8c28cSEnji Cooper```cpp 177*5ca8c28cSEnji Cooperclass NameGenerator { 178*5ca8c28cSEnji Cooper public: 179*5ca8c28cSEnji Cooper template <typename T> 180*5ca8c28cSEnji Cooper static std::string GetName(int) { 181*5ca8c28cSEnji Cooper if constexpr (std::is_same_v<T, char>) return "char"; 182*5ca8c28cSEnji Cooper if constexpr (std::is_same_v<T, int>) return "int"; 183*5ca8c28cSEnji Cooper if constexpr (std::is_same_v<T, unsigned int>) return "unsignedInt"; 184*5ca8c28cSEnji Cooper } 185*5ca8c28cSEnji Cooper}; 186*5ca8c28cSEnji CooperTYPED_TEST_SUITE(MyFixture, MyTypes, NameGenerator); 187*5ca8c28cSEnji Cooper``` 188*5ca8c28cSEnji Cooper 18928f6c2f2SEnji CooperSee also [`TYPED_TEST`](#TYPED_TEST) and 19028f6c2f2SEnji Cooper[Typed Tests](../advanced.md#typed-tests) for more information. 19128f6c2f2SEnji Cooper 19228f6c2f2SEnji Cooper### TYPED_TEST {#TYPED_TEST} 19328f6c2f2SEnji Cooper 19428f6c2f2SEnji Cooper<pre> 19528f6c2f2SEnji CooperTYPED_TEST(<em>TestSuiteName</em>, <em>TestName</em>) { 19628f6c2f2SEnji Cooper ... <em>statements</em> ... 19728f6c2f2SEnji Cooper} 19828f6c2f2SEnji Cooper</pre> 19928f6c2f2SEnji Cooper 20028f6c2f2SEnji CooperDefines an individual typed test named *`TestName`* in the typed test suite 20128f6c2f2SEnji Cooper*`TestSuiteName`*. The test suite must be defined with 20228f6c2f2SEnji Cooper[`TYPED_TEST_SUITE`](#TYPED_TEST_SUITE). 20328f6c2f2SEnji Cooper 20428f6c2f2SEnji CooperWithin the test body, the special name `TypeParam` refers to the type parameter, 20528f6c2f2SEnji Cooperand `TestFixture` refers to the fixture class. See the following example: 20628f6c2f2SEnji Cooper 20728f6c2f2SEnji Cooper```cpp 20828f6c2f2SEnji CooperTYPED_TEST(MyFixture, Example) { 20928f6c2f2SEnji Cooper // Inside a test, refer to the special name TypeParam to get the type 21028f6c2f2SEnji Cooper // parameter. Since we are inside a derived class template, C++ requires 21128f6c2f2SEnji Cooper // us to visit the members of MyFixture via 'this'. 21228f6c2f2SEnji Cooper TypeParam n = this->value_; 21328f6c2f2SEnji Cooper 21428f6c2f2SEnji Cooper // To visit static members of the fixture, add the 'TestFixture::' 21528f6c2f2SEnji Cooper // prefix. 21628f6c2f2SEnji Cooper n += TestFixture::shared_; 21728f6c2f2SEnji Cooper 21828f6c2f2SEnji Cooper // To refer to typedefs in the fixture, add the 'typename TestFixture::' 21928f6c2f2SEnji Cooper // prefix. The 'typename' is required to satisfy the compiler. 22028f6c2f2SEnji Cooper typename TestFixture::List values; 22128f6c2f2SEnji Cooper 22228f6c2f2SEnji Cooper values.push_back(n); 22328f6c2f2SEnji Cooper ... 22428f6c2f2SEnji Cooper} 22528f6c2f2SEnji Cooper``` 22628f6c2f2SEnji Cooper 22728f6c2f2SEnji CooperFor more information, see [Typed Tests](../advanced.md#typed-tests). 22828f6c2f2SEnji Cooper 22928f6c2f2SEnji Cooper### TYPED_TEST_SUITE_P {#TYPED_TEST_SUITE_P} 23028f6c2f2SEnji Cooper 23128f6c2f2SEnji Cooper`TYPED_TEST_SUITE_P(`*`TestFixtureName`*`)` 23228f6c2f2SEnji Cooper 23328f6c2f2SEnji CooperDefines a type-parameterized test suite based on the test fixture 23428f6c2f2SEnji Cooper*`TestFixtureName`*. The test suite name is *`TestFixtureName`*. 23528f6c2f2SEnji Cooper 23628f6c2f2SEnji CooperThe argument *`TestFixtureName`* is a fixture class template, parameterized by a 23728f6c2f2SEnji Coopertype. See [`TYPED_TEST_SUITE`](#TYPED_TEST_SUITE) for an example. 23828f6c2f2SEnji Cooper 23928f6c2f2SEnji CooperSee also [`TYPED_TEST_P`](#TYPED_TEST_P) and 24028f6c2f2SEnji Cooper[Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more 24128f6c2f2SEnji Cooperinformation. 24228f6c2f2SEnji Cooper 24328f6c2f2SEnji Cooper### TYPED_TEST_P {#TYPED_TEST_P} 24428f6c2f2SEnji Cooper 24528f6c2f2SEnji Cooper<pre> 24628f6c2f2SEnji CooperTYPED_TEST_P(<em>TestSuiteName</em>, <em>TestName</em>) { 24728f6c2f2SEnji Cooper ... <em>statements</em> ... 24828f6c2f2SEnji Cooper} 24928f6c2f2SEnji Cooper</pre> 25028f6c2f2SEnji Cooper 25128f6c2f2SEnji CooperDefines an individual type-parameterized test named *`TestName`* in the 25228f6c2f2SEnji Coopertype-parameterized test suite *`TestSuiteName`*. The test suite must be defined 25328f6c2f2SEnji Cooperwith [`TYPED_TEST_SUITE_P`](#TYPED_TEST_SUITE_P). 25428f6c2f2SEnji Cooper 25528f6c2f2SEnji CooperWithin the test body, the special name `TypeParam` refers to the type parameter, 25628f6c2f2SEnji Cooperand `TestFixture` refers to the fixture class. See [`TYPED_TEST`](#TYPED_TEST) 25728f6c2f2SEnji Cooperfor an example. 25828f6c2f2SEnji Cooper 25928f6c2f2SEnji CooperSee also [`REGISTER_TYPED_TEST_SUITE_P`](#REGISTER_TYPED_TEST_SUITE_P) and 26028f6c2f2SEnji Cooper[Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more 26128f6c2f2SEnji Cooperinformation. 26228f6c2f2SEnji Cooper 26328f6c2f2SEnji Cooper### REGISTER_TYPED_TEST_SUITE_P {#REGISTER_TYPED_TEST_SUITE_P} 26428f6c2f2SEnji Cooper 26528f6c2f2SEnji Cooper`REGISTER_TYPED_TEST_SUITE_P(`*`TestSuiteName`*`,`*`TestNames...`*`)` 26628f6c2f2SEnji Cooper 26728f6c2f2SEnji CooperRegisters the type-parameterized tests *`TestNames...`* of the test suite 26828f6c2f2SEnji Cooper*`TestSuiteName`*. The test suite and tests must be defined with 26928f6c2f2SEnji Cooper[`TYPED_TEST_SUITE_P`](#TYPED_TEST_SUITE_P) and [`TYPED_TEST_P`](#TYPED_TEST_P). 27028f6c2f2SEnji Cooper 27128f6c2f2SEnji CooperFor example: 27228f6c2f2SEnji Cooper 27328f6c2f2SEnji Cooper```cpp 27428f6c2f2SEnji Cooper// Define the test suite and tests. 27528f6c2f2SEnji CooperTYPED_TEST_SUITE_P(MyFixture); 27628f6c2f2SEnji CooperTYPED_TEST_P(MyFixture, HasPropertyA) { ... } 27728f6c2f2SEnji CooperTYPED_TEST_P(MyFixture, HasPropertyB) { ... } 27828f6c2f2SEnji Cooper 27928f6c2f2SEnji Cooper// Register the tests in the test suite. 28028f6c2f2SEnji CooperREGISTER_TYPED_TEST_SUITE_P(MyFixture, HasPropertyA, HasPropertyB); 28128f6c2f2SEnji Cooper``` 28228f6c2f2SEnji Cooper 28328f6c2f2SEnji CooperSee also [`INSTANTIATE_TYPED_TEST_SUITE_P`](#INSTANTIATE_TYPED_TEST_SUITE_P) and 28428f6c2f2SEnji Cooper[Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more 28528f6c2f2SEnji Cooperinformation. 28628f6c2f2SEnji Cooper 28728f6c2f2SEnji Cooper### INSTANTIATE_TYPED_TEST_SUITE_P {#INSTANTIATE_TYPED_TEST_SUITE_P} 28828f6c2f2SEnji Cooper 28928f6c2f2SEnji Cooper`INSTANTIATE_TYPED_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`Types`*`)` 29028f6c2f2SEnji Cooper 29128f6c2f2SEnji CooperInstantiates the type-parameterized test suite *`TestSuiteName`*. The test suite 29228f6c2f2SEnji Coopermust be registered with 29328f6c2f2SEnji Cooper[`REGISTER_TYPED_TEST_SUITE_P`](#REGISTER_TYPED_TEST_SUITE_P). 29428f6c2f2SEnji Cooper 29528f6c2f2SEnji CooperThe argument *`InstantiationName`* is a unique name for the instantiation of the 29628f6c2f2SEnji Coopertest suite, to distinguish between multiple instantiations. In test output, the 29728f6c2f2SEnji Cooperinstantiation name is added as a prefix to the test suite name 298*5ca8c28cSEnji Cooper*`TestSuiteName`*. If *`InstantiationName`* is empty 299*5ca8c28cSEnji Cooper(`INSTANTIATE_TYPED_TEST_SUITE_P(, ...)`), no prefix is added. 30028f6c2f2SEnji Cooper 30128f6c2f2SEnji CooperThe argument *`Types`* is a [`Types`](#Types) object representing the list of 30228f6c2f2SEnji Coopertypes to run the tests on, for example: 30328f6c2f2SEnji Cooper 30428f6c2f2SEnji Cooper```cpp 30528f6c2f2SEnji Cooperusing MyTypes = ::testing::Types<char, int, unsigned int>; 30628f6c2f2SEnji CooperINSTANTIATE_TYPED_TEST_SUITE_P(MyInstantiation, MyFixture, MyTypes); 30728f6c2f2SEnji Cooper``` 30828f6c2f2SEnji Cooper 30928f6c2f2SEnji CooperThe type alias (`using` or `typedef`) is necessary for the 31028f6c2f2SEnji Cooper`INSTANTIATE_TYPED_TEST_SUITE_P` macro to parse correctly. 31128f6c2f2SEnji Cooper 31228f6c2f2SEnji CooperFor more information, see 31328f6c2f2SEnji Cooper[Type-Parameterized Tests](../advanced.md#type-parameterized-tests). 31428f6c2f2SEnji Cooper 31528f6c2f2SEnji Cooper### FRIEND_TEST {#FRIEND_TEST} 31628f6c2f2SEnji Cooper 31728f6c2f2SEnji Cooper`FRIEND_TEST(`*`TestSuiteName`*`,`*`TestName`*`)` 31828f6c2f2SEnji Cooper 31928f6c2f2SEnji CooperWithin a class body, declares an individual test as a friend of the class, 32028f6c2f2SEnji Cooperenabling the test to access private class members. 32128f6c2f2SEnji Cooper 32228f6c2f2SEnji CooperIf the class is defined in a namespace, then in order to be friends of the 32328f6c2f2SEnji Cooperclass, test fixtures and tests must be defined in the exact same namespace, 32428f6c2f2SEnji Cooperwithout inline or anonymous namespaces. 32528f6c2f2SEnji Cooper 32628f6c2f2SEnji CooperFor example, if the class definition looks like the following: 32728f6c2f2SEnji Cooper 32828f6c2f2SEnji Cooper```cpp 32928f6c2f2SEnji Coopernamespace my_namespace { 33028f6c2f2SEnji Cooper 33128f6c2f2SEnji Cooperclass MyClass { 33228f6c2f2SEnji Cooper friend class MyClassTest; 33328f6c2f2SEnji Cooper FRIEND_TEST(MyClassTest, HasPropertyA); 33428f6c2f2SEnji Cooper FRIEND_TEST(MyClassTest, HasPropertyB); 33528f6c2f2SEnji Cooper ... definition of class MyClass ... 33628f6c2f2SEnji Cooper}; 33728f6c2f2SEnji Cooper 33828f6c2f2SEnji Cooper} // namespace my_namespace 33928f6c2f2SEnji Cooper``` 34028f6c2f2SEnji Cooper 34128f6c2f2SEnji CooperThen the test code should look like: 34228f6c2f2SEnji Cooper 34328f6c2f2SEnji Cooper```cpp 34428f6c2f2SEnji Coopernamespace my_namespace { 34528f6c2f2SEnji Cooper 34628f6c2f2SEnji Cooperclass MyClassTest : public testing::Test { 34728f6c2f2SEnji Cooper ... 34828f6c2f2SEnji Cooper}; 34928f6c2f2SEnji Cooper 35028f6c2f2SEnji CooperTEST_F(MyClassTest, HasPropertyA) { ... } 35128f6c2f2SEnji CooperTEST_F(MyClassTest, HasPropertyB) { ... } 35228f6c2f2SEnji Cooper 35328f6c2f2SEnji Cooper} // namespace my_namespace 35428f6c2f2SEnji Cooper``` 35528f6c2f2SEnji Cooper 35628f6c2f2SEnji CooperSee [Testing Private Code](../advanced.md#testing-private-code) for more 35728f6c2f2SEnji Cooperinformation. 35828f6c2f2SEnji Cooper 35928f6c2f2SEnji Cooper### SCOPED_TRACE {#SCOPED_TRACE} 36028f6c2f2SEnji Cooper 36128f6c2f2SEnji Cooper`SCOPED_TRACE(`*`message`*`)` 36228f6c2f2SEnji Cooper 36328f6c2f2SEnji CooperCauses the current file name, line number, and the given message *`message`* to 36428f6c2f2SEnji Cooperbe added to the failure message for each assertion failure that occurs in the 36528f6c2f2SEnji Cooperscope. 36628f6c2f2SEnji Cooper 36728f6c2f2SEnji CooperFor more information, see 36828f6c2f2SEnji Cooper[Adding Traces to Assertions](../advanced.md#adding-traces-to-assertions). 36928f6c2f2SEnji Cooper 37028f6c2f2SEnji CooperSee also the [`ScopedTrace` class](#ScopedTrace). 37128f6c2f2SEnji Cooper 37228f6c2f2SEnji Cooper### GTEST_SKIP {#GTEST_SKIP} 37328f6c2f2SEnji Cooper 37428f6c2f2SEnji Cooper`GTEST_SKIP()` 37528f6c2f2SEnji Cooper 37628f6c2f2SEnji CooperPrevents further test execution at runtime. 37728f6c2f2SEnji Cooper 37828f6c2f2SEnji CooperCan be used in individual test cases or in the `SetUp()` methods of test 37928f6c2f2SEnji Cooperenvironments or test fixtures (classes derived from the 38028f6c2f2SEnji Cooper[`Environment`](#Environment) or [`Test`](#Test) classes). If used in a global 38128f6c2f2SEnji Coopertest environment `SetUp()` method, it skips all tests in the test program. If 38228f6c2f2SEnji Cooperused in a test fixture `SetUp()` method, it skips all tests in the corresponding 38328f6c2f2SEnji Coopertest suite. 38428f6c2f2SEnji Cooper 38528f6c2f2SEnji CooperSimilar to assertions, `GTEST_SKIP` allows streaming a custom message into it. 38628f6c2f2SEnji Cooper 38728f6c2f2SEnji CooperSee [Skipping Test Execution](../advanced.md#skipping-test-execution) for more 38828f6c2f2SEnji Cooperinformation. 38928f6c2f2SEnji Cooper 39028f6c2f2SEnji Cooper### GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST {#GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST} 39128f6c2f2SEnji Cooper 39228f6c2f2SEnji Cooper`GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(`*`TestSuiteName`*`)` 39328f6c2f2SEnji Cooper 39428f6c2f2SEnji CooperAllows the value-parameterized test suite *`TestSuiteName`* to be 39528f6c2f2SEnji Cooperuninstantiated. 39628f6c2f2SEnji Cooper 39728f6c2f2SEnji CooperBy default, every [`TEST_P`](#TEST_P) call without a corresponding 39828f6c2f2SEnji Cooper[`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P) call causes a failing 39928f6c2f2SEnji Coopertest in the test suite `GoogleTestVerification`. 40028f6c2f2SEnji Cooper`GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST` suppresses this failure for the 40128f6c2f2SEnji Coopergiven test suite. 40228f6c2f2SEnji Cooper 40328f6c2f2SEnji Cooper## Classes and types 40428f6c2f2SEnji Cooper 40528f6c2f2SEnji CooperGoogleTest defines the following classes and types to help with writing tests. 40628f6c2f2SEnji Cooper 40728f6c2f2SEnji Cooper### AssertionResult {#AssertionResult} 40828f6c2f2SEnji Cooper 40928f6c2f2SEnji Cooper`testing::AssertionResult` 41028f6c2f2SEnji Cooper 41128f6c2f2SEnji CooperA class for indicating whether an assertion was successful. 41228f6c2f2SEnji Cooper 41328f6c2f2SEnji CooperWhen the assertion wasn't successful, the `AssertionResult` object stores a 41428f6c2f2SEnji Coopernon-empty failure message that can be retrieved with the object's `message()` 41528f6c2f2SEnji Coopermethod. 41628f6c2f2SEnji Cooper 41728f6c2f2SEnji CooperTo create an instance of this class, use one of the factory functions 41828f6c2f2SEnji Cooper[`AssertionSuccess()`](#AssertionSuccess) or 41928f6c2f2SEnji Cooper[`AssertionFailure()`](#AssertionFailure). 42028f6c2f2SEnji Cooper 42128f6c2f2SEnji Cooper### AssertionException {#AssertionException} 42228f6c2f2SEnji Cooper 42328f6c2f2SEnji Cooper`testing::AssertionException` 42428f6c2f2SEnji Cooper 42528f6c2f2SEnji CooperException which can be thrown from 42628f6c2f2SEnji Cooper[`TestEventListener::OnTestPartResult`](#TestEventListener::OnTestPartResult). 42728f6c2f2SEnji Cooper 42828f6c2f2SEnji Cooper### EmptyTestEventListener {#EmptyTestEventListener} 42928f6c2f2SEnji Cooper 43028f6c2f2SEnji Cooper`testing::EmptyTestEventListener` 43128f6c2f2SEnji Cooper 43228f6c2f2SEnji CooperProvides an empty implementation of all methods in the 43328f6c2f2SEnji Cooper[`TestEventListener`](#TestEventListener) interface, such that a subclass only 43428f6c2f2SEnji Cooperneeds to override the methods it cares about. 43528f6c2f2SEnji Cooper 43628f6c2f2SEnji Cooper### Environment {#Environment} 43728f6c2f2SEnji Cooper 43828f6c2f2SEnji Cooper`testing::Environment` 43928f6c2f2SEnji Cooper 44028f6c2f2SEnji CooperRepresents a global test environment. See 44128f6c2f2SEnji Cooper[Global Set-Up and Tear-Down](../advanced.md#global-set-up-and-tear-down). 44228f6c2f2SEnji Cooper 44328f6c2f2SEnji Cooper#### Protected Methods {#Environment-protected} 44428f6c2f2SEnji Cooper 44528f6c2f2SEnji Cooper##### SetUp {#Environment::SetUp} 44628f6c2f2SEnji Cooper 44728f6c2f2SEnji Cooper`virtual void Environment::SetUp()` 44828f6c2f2SEnji Cooper 44928f6c2f2SEnji CooperOverride this to define how to set up the environment. 45028f6c2f2SEnji Cooper 45128f6c2f2SEnji Cooper##### TearDown {#Environment::TearDown} 45228f6c2f2SEnji Cooper 45328f6c2f2SEnji Cooper`virtual void Environment::TearDown()` 45428f6c2f2SEnji Cooper 45528f6c2f2SEnji CooperOverride this to define how to tear down the environment. 45628f6c2f2SEnji Cooper 45728f6c2f2SEnji Cooper### ScopedTrace {#ScopedTrace} 45828f6c2f2SEnji Cooper 45928f6c2f2SEnji Cooper`testing::ScopedTrace` 46028f6c2f2SEnji Cooper 46128f6c2f2SEnji CooperAn instance of this class causes a trace to be included in every test failure 46228f6c2f2SEnji Coopermessage generated by code in the scope of the lifetime of the `ScopedTrace` 46328f6c2f2SEnji Cooperinstance. The effect is undone with the destruction of the instance. 46428f6c2f2SEnji Cooper 46528f6c2f2SEnji CooperThe `ScopedTrace` constructor has the following form: 46628f6c2f2SEnji Cooper 46728f6c2f2SEnji Cooper```cpp 46828f6c2f2SEnji Coopertemplate <typename T> 46928f6c2f2SEnji CooperScopedTrace(const char* file, int line, const T& message) 47028f6c2f2SEnji Cooper``` 47128f6c2f2SEnji Cooper 47228f6c2f2SEnji CooperExample usage: 47328f6c2f2SEnji Cooper 47428f6c2f2SEnji Cooper```cpp 47528f6c2f2SEnji Coopertesting::ScopedTrace trace("file.cc", 123, "message"); 47628f6c2f2SEnji Cooper``` 47728f6c2f2SEnji Cooper 47828f6c2f2SEnji CooperThe resulting trace includes the given source file path and line number, and the 47928f6c2f2SEnji Coopergiven message. The `message` argument can be anything streamable to 48028f6c2f2SEnji Cooper`std::ostream`. 48128f6c2f2SEnji Cooper 48228f6c2f2SEnji CooperSee also [`SCOPED_TRACE`](#SCOPED_TRACE). 48328f6c2f2SEnji Cooper 48428f6c2f2SEnji Cooper### Test {#Test} 48528f6c2f2SEnji Cooper 48628f6c2f2SEnji Cooper`testing::Test` 48728f6c2f2SEnji Cooper 48828f6c2f2SEnji CooperThe abstract class that all tests inherit from. `Test` is not copyable. 48928f6c2f2SEnji Cooper 49028f6c2f2SEnji Cooper#### Public Methods {#Test-public} 49128f6c2f2SEnji Cooper 49228f6c2f2SEnji Cooper##### SetUpTestSuite {#Test::SetUpTestSuite} 49328f6c2f2SEnji Cooper 49428f6c2f2SEnji Cooper`static void Test::SetUpTestSuite()` 49528f6c2f2SEnji Cooper 49628f6c2f2SEnji CooperPerforms shared setup for all tests in the test suite. GoogleTest calls 49728f6c2f2SEnji Cooper`SetUpTestSuite()` before running the first test in the test suite. 49828f6c2f2SEnji Cooper 49928f6c2f2SEnji Cooper##### TearDownTestSuite {#Test::TearDownTestSuite} 50028f6c2f2SEnji Cooper 50128f6c2f2SEnji Cooper`static void Test::TearDownTestSuite()` 50228f6c2f2SEnji Cooper 50328f6c2f2SEnji CooperPerforms shared teardown for all tests in the test suite. GoogleTest calls 50428f6c2f2SEnji Cooper`TearDownTestSuite()` after running the last test in the test suite. 50528f6c2f2SEnji Cooper 50628f6c2f2SEnji Cooper##### HasFatalFailure {#Test::HasFatalFailure} 50728f6c2f2SEnji Cooper 50828f6c2f2SEnji Cooper`static bool Test::HasFatalFailure()` 50928f6c2f2SEnji Cooper 51028f6c2f2SEnji CooperReturns true if and only if the current test has a fatal failure. 51128f6c2f2SEnji Cooper 51228f6c2f2SEnji Cooper##### HasNonfatalFailure {#Test::HasNonfatalFailure} 51328f6c2f2SEnji Cooper 51428f6c2f2SEnji Cooper`static bool Test::HasNonfatalFailure()` 51528f6c2f2SEnji Cooper 51628f6c2f2SEnji CooperReturns true if and only if the current test has a nonfatal failure. 51728f6c2f2SEnji Cooper 51828f6c2f2SEnji Cooper##### HasFailure {#Test::HasFailure} 51928f6c2f2SEnji Cooper 52028f6c2f2SEnji Cooper`static bool Test::HasFailure()` 52128f6c2f2SEnji Cooper 52228f6c2f2SEnji CooperReturns true if and only if the current test has any failure, either fatal or 52328f6c2f2SEnji Coopernonfatal. 52428f6c2f2SEnji Cooper 52528f6c2f2SEnji Cooper##### IsSkipped {#Test::IsSkipped} 52628f6c2f2SEnji Cooper 52728f6c2f2SEnji Cooper`static bool Test::IsSkipped()` 52828f6c2f2SEnji Cooper 52928f6c2f2SEnji CooperReturns true if and only if the current test was skipped. 53028f6c2f2SEnji Cooper 53128f6c2f2SEnji Cooper##### RecordProperty {#Test::RecordProperty} 53228f6c2f2SEnji Cooper 53328f6c2f2SEnji Cooper`static void Test::RecordProperty(const std::string& key, const std::string& 53428f6c2f2SEnji Coopervalue)` \ 53528f6c2f2SEnji Cooper`static void Test::RecordProperty(const std::string& key, int value)` 53628f6c2f2SEnji Cooper 53728f6c2f2SEnji CooperLogs a property for the current test, test suite, or entire invocation of the 53828f6c2f2SEnji Coopertest program. Only the last value for a given key is logged. 53928f6c2f2SEnji Cooper 54028f6c2f2SEnji CooperThe key must be a valid XML attribute name, and cannot conflict with the ones 54128f6c2f2SEnji Cooperalready used by GoogleTest (`name`, `file`, `line`, `status`, `time`, 54228f6c2f2SEnji Cooper`classname`, `type_param`, and `value_param`). 54328f6c2f2SEnji Cooper 54428f6c2f2SEnji Cooper`RecordProperty` is `public static` so it can be called from utility functions 54528f6c2f2SEnji Cooperthat are not members of the test fixture. 54628f6c2f2SEnji Cooper 54728f6c2f2SEnji CooperCalls to `RecordProperty` made during the lifespan of the test (from the moment 54828f6c2f2SEnji Cooperits constructor starts to the moment its destructor finishes) are output in XML 54928f6c2f2SEnji Cooperas attributes of the `<testcase>` element. Properties recorded from a fixture's 55028f6c2f2SEnji Cooper`SetUpTestSuite` or `TearDownTestSuite` methods are logged as attributes of the 55128f6c2f2SEnji Coopercorresponding `<testsuite>` element. Calls to `RecordProperty` made in the 55228f6c2f2SEnji Cooperglobal context (before or after invocation of `RUN_ALL_TESTS` or from the 55328f6c2f2SEnji Cooper`SetUp`/`TearDown` methods of registered `Environment` objects) are output as 55428f6c2f2SEnji Cooperattributes of the `<testsuites>` element. 55528f6c2f2SEnji Cooper 55628f6c2f2SEnji Cooper#### Protected Methods {#Test-protected} 55728f6c2f2SEnji Cooper 55828f6c2f2SEnji Cooper##### SetUp {#Test::SetUp} 55928f6c2f2SEnji Cooper 56028f6c2f2SEnji Cooper`virtual void Test::SetUp()` 56128f6c2f2SEnji Cooper 56228f6c2f2SEnji CooperOverride this to perform test fixture setup. GoogleTest calls `SetUp()` before 56328f6c2f2SEnji Cooperrunning each individual test. 56428f6c2f2SEnji Cooper 56528f6c2f2SEnji Cooper##### TearDown {#Test::TearDown} 56628f6c2f2SEnji Cooper 56728f6c2f2SEnji Cooper`virtual void Test::TearDown()` 56828f6c2f2SEnji Cooper 56928f6c2f2SEnji CooperOverride this to perform test fixture teardown. GoogleTest calls `TearDown()` 57028f6c2f2SEnji Cooperafter running each individual test. 57128f6c2f2SEnji Cooper 57228f6c2f2SEnji Cooper### TestWithParam {#TestWithParam} 57328f6c2f2SEnji Cooper 57428f6c2f2SEnji Cooper`testing::TestWithParam<T>` 57528f6c2f2SEnji Cooper 57628f6c2f2SEnji CooperA convenience class which inherits from both [`Test`](#Test) and 57728f6c2f2SEnji Cooper[`WithParamInterface<T>`](#WithParamInterface). 57828f6c2f2SEnji Cooper 57928f6c2f2SEnji Cooper### TestSuite {#TestSuite} 58028f6c2f2SEnji Cooper 58128f6c2f2SEnji CooperRepresents a test suite. `TestSuite` is not copyable. 58228f6c2f2SEnji Cooper 58328f6c2f2SEnji Cooper#### Public Methods {#TestSuite-public} 58428f6c2f2SEnji Cooper 58528f6c2f2SEnji Cooper##### name {#TestSuite::name} 58628f6c2f2SEnji Cooper 58728f6c2f2SEnji Cooper`const char* TestSuite::name() const` 58828f6c2f2SEnji Cooper 58928f6c2f2SEnji CooperGets the name of the test suite. 59028f6c2f2SEnji Cooper 59128f6c2f2SEnji Cooper##### type_param {#TestSuite::type_param} 59228f6c2f2SEnji Cooper 59328f6c2f2SEnji Cooper`const char* TestSuite::type_param() const` 59428f6c2f2SEnji Cooper 59528f6c2f2SEnji CooperReturns the name of the parameter type, or `NULL` if this is not a typed or 59628f6c2f2SEnji Coopertype-parameterized test suite. See [Typed Tests](../advanced.md#typed-tests) and 59728f6c2f2SEnji Cooper[Type-Parameterized Tests](../advanced.md#type-parameterized-tests). 59828f6c2f2SEnji Cooper 59928f6c2f2SEnji Cooper##### should_run {#TestSuite::should_run} 60028f6c2f2SEnji Cooper 60128f6c2f2SEnji Cooper`bool TestSuite::should_run() const` 60228f6c2f2SEnji Cooper 60328f6c2f2SEnji CooperReturns true if any test in this test suite should run. 60428f6c2f2SEnji Cooper 60528f6c2f2SEnji Cooper##### successful_test_count {#TestSuite::successful_test_count} 60628f6c2f2SEnji Cooper 60728f6c2f2SEnji Cooper`int TestSuite::successful_test_count() const` 60828f6c2f2SEnji Cooper 60928f6c2f2SEnji CooperGets the number of successful tests in this test suite. 61028f6c2f2SEnji Cooper 61128f6c2f2SEnji Cooper##### skipped_test_count {#TestSuite::skipped_test_count} 61228f6c2f2SEnji Cooper 61328f6c2f2SEnji Cooper`int TestSuite::skipped_test_count() const` 61428f6c2f2SEnji Cooper 61528f6c2f2SEnji CooperGets the number of skipped tests in this test suite. 61628f6c2f2SEnji Cooper 61728f6c2f2SEnji Cooper##### failed_test_count {#TestSuite::failed_test_count} 61828f6c2f2SEnji Cooper 61928f6c2f2SEnji Cooper`int TestSuite::failed_test_count() const` 62028f6c2f2SEnji Cooper 62128f6c2f2SEnji CooperGets the number of failed tests in this test suite. 62228f6c2f2SEnji Cooper 62328f6c2f2SEnji Cooper##### reportable_disabled_test_count {#TestSuite::reportable_disabled_test_count} 62428f6c2f2SEnji Cooper 62528f6c2f2SEnji Cooper`int TestSuite::reportable_disabled_test_count() const` 62628f6c2f2SEnji Cooper 62728f6c2f2SEnji CooperGets the number of disabled tests that will be reported in the XML report. 62828f6c2f2SEnji Cooper 62928f6c2f2SEnji Cooper##### disabled_test_count {#TestSuite::disabled_test_count} 63028f6c2f2SEnji Cooper 63128f6c2f2SEnji Cooper`int TestSuite::disabled_test_count() const` 63228f6c2f2SEnji Cooper 63328f6c2f2SEnji CooperGets the number of disabled tests in this test suite. 63428f6c2f2SEnji Cooper 63528f6c2f2SEnji Cooper##### reportable_test_count {#TestSuite::reportable_test_count} 63628f6c2f2SEnji Cooper 63728f6c2f2SEnji Cooper`int TestSuite::reportable_test_count() const` 63828f6c2f2SEnji Cooper 63928f6c2f2SEnji CooperGets the number of tests to be printed in the XML report. 64028f6c2f2SEnji Cooper 64128f6c2f2SEnji Cooper##### test_to_run_count {#TestSuite::test_to_run_count} 64228f6c2f2SEnji Cooper 64328f6c2f2SEnji Cooper`int TestSuite::test_to_run_count() const` 64428f6c2f2SEnji Cooper 64528f6c2f2SEnji CooperGet the number of tests in this test suite that should run. 64628f6c2f2SEnji Cooper 64728f6c2f2SEnji Cooper##### total_test_count {#TestSuite::total_test_count} 64828f6c2f2SEnji Cooper 64928f6c2f2SEnji Cooper`int TestSuite::total_test_count() const` 65028f6c2f2SEnji Cooper 65128f6c2f2SEnji CooperGets the number of all tests in this test suite. 65228f6c2f2SEnji Cooper 65328f6c2f2SEnji Cooper##### Passed {#TestSuite::Passed} 65428f6c2f2SEnji Cooper 65528f6c2f2SEnji Cooper`bool TestSuite::Passed() const` 65628f6c2f2SEnji Cooper 65728f6c2f2SEnji CooperReturns true if and only if the test suite passed. 65828f6c2f2SEnji Cooper 65928f6c2f2SEnji Cooper##### Failed {#TestSuite::Failed} 66028f6c2f2SEnji Cooper 66128f6c2f2SEnji Cooper`bool TestSuite::Failed() const` 66228f6c2f2SEnji Cooper 66328f6c2f2SEnji CooperReturns true if and only if the test suite failed. 66428f6c2f2SEnji Cooper 66528f6c2f2SEnji Cooper##### elapsed_time {#TestSuite::elapsed_time} 66628f6c2f2SEnji Cooper 66728f6c2f2SEnji Cooper`TimeInMillis TestSuite::elapsed_time() const` 66828f6c2f2SEnji Cooper 66928f6c2f2SEnji CooperReturns the elapsed time, in milliseconds. 67028f6c2f2SEnji Cooper 67128f6c2f2SEnji Cooper##### start_timestamp {#TestSuite::start_timestamp} 67228f6c2f2SEnji Cooper 67328f6c2f2SEnji Cooper`TimeInMillis TestSuite::start_timestamp() const` 67428f6c2f2SEnji Cooper 67528f6c2f2SEnji CooperGets the time of the test suite start, in ms from the start of the UNIX epoch. 67628f6c2f2SEnji Cooper 67728f6c2f2SEnji Cooper##### GetTestInfo {#TestSuite::GetTestInfo} 67828f6c2f2SEnji Cooper 67928f6c2f2SEnji Cooper`const TestInfo* TestSuite::GetTestInfo(int i) const` 68028f6c2f2SEnji Cooper 68128f6c2f2SEnji CooperReturns the [`TestInfo`](#TestInfo) for the `i`-th test among all the tests. `i` 68228f6c2f2SEnji Coopercan range from 0 to `total_test_count() - 1`. If `i` is not in that range, 68328f6c2f2SEnji Cooperreturns `NULL`. 68428f6c2f2SEnji Cooper 68528f6c2f2SEnji Cooper##### ad_hoc_test_result {#TestSuite::ad_hoc_test_result} 68628f6c2f2SEnji Cooper 68728f6c2f2SEnji Cooper`const TestResult& TestSuite::ad_hoc_test_result() const` 68828f6c2f2SEnji Cooper 68928f6c2f2SEnji CooperReturns the [`TestResult`](#TestResult) that holds test properties recorded 69028f6c2f2SEnji Cooperduring execution of `SetUpTestSuite` and `TearDownTestSuite`. 69128f6c2f2SEnji Cooper 69228f6c2f2SEnji Cooper### TestInfo {#TestInfo} 69328f6c2f2SEnji Cooper 69428f6c2f2SEnji Cooper`testing::TestInfo` 69528f6c2f2SEnji Cooper 69628f6c2f2SEnji CooperStores information about a test. 69728f6c2f2SEnji Cooper 69828f6c2f2SEnji Cooper#### Public Methods {#TestInfo-public} 69928f6c2f2SEnji Cooper 70028f6c2f2SEnji Cooper##### test_suite_name {#TestInfo::test_suite_name} 70128f6c2f2SEnji Cooper 70228f6c2f2SEnji Cooper`const char* TestInfo::test_suite_name() const` 70328f6c2f2SEnji Cooper 70428f6c2f2SEnji CooperReturns the test suite name. 70528f6c2f2SEnji Cooper 70628f6c2f2SEnji Cooper##### name {#TestInfo::name} 70728f6c2f2SEnji Cooper 70828f6c2f2SEnji Cooper`const char* TestInfo::name() const` 70928f6c2f2SEnji Cooper 71028f6c2f2SEnji CooperReturns the test name. 71128f6c2f2SEnji Cooper 71228f6c2f2SEnji Cooper##### type_param {#TestInfo::type_param} 71328f6c2f2SEnji Cooper 71428f6c2f2SEnji Cooper`const char* TestInfo::type_param() const` 71528f6c2f2SEnji Cooper 71628f6c2f2SEnji CooperReturns the name of the parameter type, or `NULL` if this is not a typed or 71728f6c2f2SEnji Coopertype-parameterized test. See [Typed Tests](../advanced.md#typed-tests) and 71828f6c2f2SEnji Cooper[Type-Parameterized Tests](../advanced.md#type-parameterized-tests). 71928f6c2f2SEnji Cooper 72028f6c2f2SEnji Cooper##### value_param {#TestInfo::value_param} 72128f6c2f2SEnji Cooper 72228f6c2f2SEnji Cooper`const char* TestInfo::value_param() const` 72328f6c2f2SEnji Cooper 72428f6c2f2SEnji CooperReturns the text representation of the value parameter, or `NULL` if this is not 72528f6c2f2SEnji Coopera value-parameterized test. See 72628f6c2f2SEnji Cooper[Value-Parameterized Tests](../advanced.md#value-parameterized-tests). 72728f6c2f2SEnji Cooper 72828f6c2f2SEnji Cooper##### file {#TestInfo::file} 72928f6c2f2SEnji Cooper 73028f6c2f2SEnji Cooper`const char* TestInfo::file() const` 73128f6c2f2SEnji Cooper 73228f6c2f2SEnji CooperReturns the file name where this test is defined. 73328f6c2f2SEnji Cooper 73428f6c2f2SEnji Cooper##### line {#TestInfo::line} 73528f6c2f2SEnji Cooper 73628f6c2f2SEnji Cooper`int TestInfo::line() const` 73728f6c2f2SEnji Cooper 73828f6c2f2SEnji CooperReturns the line where this test is defined. 73928f6c2f2SEnji Cooper 74028f6c2f2SEnji Cooper##### is_in_another_shard {#TestInfo::is_in_another_shard} 74128f6c2f2SEnji Cooper 74228f6c2f2SEnji Cooper`bool TestInfo::is_in_another_shard() const` 74328f6c2f2SEnji Cooper 74428f6c2f2SEnji CooperReturns true if this test should not be run because it's in another shard. 74528f6c2f2SEnji Cooper 74628f6c2f2SEnji Cooper##### should_run {#TestInfo::should_run} 74728f6c2f2SEnji Cooper 74828f6c2f2SEnji Cooper`bool TestInfo::should_run() const` 74928f6c2f2SEnji Cooper 75028f6c2f2SEnji CooperReturns true if this test should run, that is if the test is not disabled (or it 75128f6c2f2SEnji Cooperis disabled but the `also_run_disabled_tests` flag has been specified) and its 75228f6c2f2SEnji Cooperfull name matches the user-specified filter. 75328f6c2f2SEnji Cooper 75428f6c2f2SEnji CooperGoogleTest allows the user to filter the tests by their full names. Only the 75528f6c2f2SEnji Coopertests that match the filter will run. See 75628f6c2f2SEnji Cooper[Running a Subset of the Tests](../advanced.md#running-a-subset-of-the-tests) 75728f6c2f2SEnji Cooperfor more information. 75828f6c2f2SEnji Cooper 75928f6c2f2SEnji Cooper##### is_reportable {#TestInfo::is_reportable} 76028f6c2f2SEnji Cooper 76128f6c2f2SEnji Cooper`bool TestInfo::is_reportable() const` 76228f6c2f2SEnji Cooper 76328f6c2f2SEnji CooperReturns true if and only if this test will appear in the XML report. 76428f6c2f2SEnji Cooper 76528f6c2f2SEnji Cooper##### result {#TestInfo::result} 76628f6c2f2SEnji Cooper 76728f6c2f2SEnji Cooper`const TestResult* TestInfo::result() const` 76828f6c2f2SEnji Cooper 76928f6c2f2SEnji CooperReturns the result of the test. See [`TestResult`](#TestResult). 77028f6c2f2SEnji Cooper 77128f6c2f2SEnji Cooper### TestParamInfo {#TestParamInfo} 77228f6c2f2SEnji Cooper 77328f6c2f2SEnji Cooper`testing::TestParamInfo<T>` 77428f6c2f2SEnji Cooper 77528f6c2f2SEnji CooperDescribes a parameter to a value-parameterized test. The type `T` is the type of 77628f6c2f2SEnji Cooperthe parameter. 77728f6c2f2SEnji Cooper 77828f6c2f2SEnji CooperContains the fields `param` and `index` which hold the value of the parameter 77928f6c2f2SEnji Cooperand its integer index respectively. 78028f6c2f2SEnji Cooper 78128f6c2f2SEnji Cooper### UnitTest {#UnitTest} 78228f6c2f2SEnji Cooper 78328f6c2f2SEnji Cooper`testing::UnitTest` 78428f6c2f2SEnji Cooper 78528f6c2f2SEnji CooperThis class contains information about the test program. 78628f6c2f2SEnji Cooper 78728f6c2f2SEnji Cooper`UnitTest` is a singleton class. The only instance is created when 78828f6c2f2SEnji Cooper`UnitTest::GetInstance()` is first called. This instance is never deleted. 78928f6c2f2SEnji Cooper 79028f6c2f2SEnji Cooper`UnitTest` is not copyable. 79128f6c2f2SEnji Cooper 79228f6c2f2SEnji Cooper#### Public Methods {#UnitTest-public} 79328f6c2f2SEnji Cooper 79428f6c2f2SEnji Cooper##### GetInstance {#UnitTest::GetInstance} 79528f6c2f2SEnji Cooper 79628f6c2f2SEnji Cooper`static UnitTest* UnitTest::GetInstance()` 79728f6c2f2SEnji Cooper 79828f6c2f2SEnji CooperGets the singleton `UnitTest` object. The first time this method is called, a 79928f6c2f2SEnji Cooper`UnitTest` object is constructed and returned. Consecutive calls will return the 80028f6c2f2SEnji Coopersame object. 80128f6c2f2SEnji Cooper 80228f6c2f2SEnji Cooper##### original_working_dir {#UnitTest::original_working_dir} 80328f6c2f2SEnji Cooper 80428f6c2f2SEnji Cooper`const char* UnitTest::original_working_dir() const` 80528f6c2f2SEnji Cooper 80628f6c2f2SEnji CooperReturns the working directory when the first [`TEST()`](#TEST) or 80728f6c2f2SEnji Cooper[`TEST_F()`](#TEST_F) was executed. The `UnitTest` object owns the string. 80828f6c2f2SEnji Cooper 80928f6c2f2SEnji Cooper##### current_test_suite {#UnitTest::current_test_suite} 81028f6c2f2SEnji Cooper 81128f6c2f2SEnji Cooper`const TestSuite* UnitTest::current_test_suite() const` 81228f6c2f2SEnji Cooper 81328f6c2f2SEnji CooperReturns the [`TestSuite`](#TestSuite) object for the test that's currently 81428f6c2f2SEnji Cooperrunning, or `NULL` if no test is running. 81528f6c2f2SEnji Cooper 81628f6c2f2SEnji Cooper##### current_test_info {#UnitTest::current_test_info} 81728f6c2f2SEnji Cooper 81828f6c2f2SEnji Cooper`const TestInfo* UnitTest::current_test_info() const` 81928f6c2f2SEnji Cooper 82028f6c2f2SEnji CooperReturns the [`TestInfo`](#TestInfo) object for the test that's currently 82128f6c2f2SEnji Cooperrunning, or `NULL` if no test is running. 82228f6c2f2SEnji Cooper 82328f6c2f2SEnji Cooper##### random_seed {#UnitTest::random_seed} 82428f6c2f2SEnji Cooper 82528f6c2f2SEnji Cooper`int UnitTest::random_seed() const` 82628f6c2f2SEnji Cooper 82728f6c2f2SEnji CooperReturns the random seed used at the start of the current test run. 82828f6c2f2SEnji Cooper 82928f6c2f2SEnji Cooper##### successful_test_suite_count {#UnitTest::successful_test_suite_count} 83028f6c2f2SEnji Cooper 83128f6c2f2SEnji Cooper`int UnitTest::successful_test_suite_count() const` 83228f6c2f2SEnji Cooper 83328f6c2f2SEnji CooperGets the number of successful test suites. 83428f6c2f2SEnji Cooper 83528f6c2f2SEnji Cooper##### failed_test_suite_count {#UnitTest::failed_test_suite_count} 83628f6c2f2SEnji Cooper 83728f6c2f2SEnji Cooper`int UnitTest::failed_test_suite_count() const` 83828f6c2f2SEnji Cooper 83928f6c2f2SEnji CooperGets the number of failed test suites. 84028f6c2f2SEnji Cooper 84128f6c2f2SEnji Cooper##### total_test_suite_count {#UnitTest::total_test_suite_count} 84228f6c2f2SEnji Cooper 84328f6c2f2SEnji Cooper`int UnitTest::total_test_suite_count() const` 84428f6c2f2SEnji Cooper 84528f6c2f2SEnji CooperGets the number of all test suites. 84628f6c2f2SEnji Cooper 84728f6c2f2SEnji Cooper##### test_suite_to_run_count {#UnitTest::test_suite_to_run_count} 84828f6c2f2SEnji Cooper 84928f6c2f2SEnji Cooper`int UnitTest::test_suite_to_run_count() const` 85028f6c2f2SEnji Cooper 85128f6c2f2SEnji CooperGets the number of all test suites that contain at least one test that should 85228f6c2f2SEnji Cooperrun. 85328f6c2f2SEnji Cooper 85428f6c2f2SEnji Cooper##### successful_test_count {#UnitTest::successful_test_count} 85528f6c2f2SEnji Cooper 85628f6c2f2SEnji Cooper`int UnitTest::successful_test_count() const` 85728f6c2f2SEnji Cooper 85828f6c2f2SEnji CooperGets the number of successful tests. 85928f6c2f2SEnji Cooper 86028f6c2f2SEnji Cooper##### skipped_test_count {#UnitTest::skipped_test_count} 86128f6c2f2SEnji Cooper 86228f6c2f2SEnji Cooper`int UnitTest::skipped_test_count() const` 86328f6c2f2SEnji Cooper 86428f6c2f2SEnji CooperGets the number of skipped tests. 86528f6c2f2SEnji Cooper 86628f6c2f2SEnji Cooper##### failed_test_count {#UnitTest::failed_test_count} 86728f6c2f2SEnji Cooper 86828f6c2f2SEnji Cooper`int UnitTest::failed_test_count() const` 86928f6c2f2SEnji Cooper 87028f6c2f2SEnji CooperGets the number of failed tests. 87128f6c2f2SEnji Cooper 87228f6c2f2SEnji Cooper##### reportable_disabled_test_count {#UnitTest::reportable_disabled_test_count} 87328f6c2f2SEnji Cooper 87428f6c2f2SEnji Cooper`int UnitTest::reportable_disabled_test_count() const` 87528f6c2f2SEnji Cooper 87628f6c2f2SEnji CooperGets the number of disabled tests that will be reported in the XML report. 87728f6c2f2SEnji Cooper 87828f6c2f2SEnji Cooper##### disabled_test_count {#UnitTest::disabled_test_count} 87928f6c2f2SEnji Cooper 88028f6c2f2SEnji Cooper`int UnitTest::disabled_test_count() const` 88128f6c2f2SEnji Cooper 88228f6c2f2SEnji CooperGets the number of disabled tests. 88328f6c2f2SEnji Cooper 88428f6c2f2SEnji Cooper##### reportable_test_count {#UnitTest::reportable_test_count} 88528f6c2f2SEnji Cooper 88628f6c2f2SEnji Cooper`int UnitTest::reportable_test_count() const` 88728f6c2f2SEnji Cooper 88828f6c2f2SEnji CooperGets the number of tests to be printed in the XML report. 88928f6c2f2SEnji Cooper 89028f6c2f2SEnji Cooper##### total_test_count {#UnitTest::total_test_count} 89128f6c2f2SEnji Cooper 89228f6c2f2SEnji Cooper`int UnitTest::total_test_count() const` 89328f6c2f2SEnji Cooper 89428f6c2f2SEnji CooperGets the number of all tests. 89528f6c2f2SEnji Cooper 89628f6c2f2SEnji Cooper##### test_to_run_count {#UnitTest::test_to_run_count} 89728f6c2f2SEnji Cooper 89828f6c2f2SEnji Cooper`int UnitTest::test_to_run_count() const` 89928f6c2f2SEnji Cooper 90028f6c2f2SEnji CooperGets the number of tests that should run. 90128f6c2f2SEnji Cooper 90228f6c2f2SEnji Cooper##### start_timestamp {#UnitTest::start_timestamp} 90328f6c2f2SEnji Cooper 90428f6c2f2SEnji Cooper`TimeInMillis UnitTest::start_timestamp() const` 90528f6c2f2SEnji Cooper 90628f6c2f2SEnji CooperGets the time of the test program start, in ms from the start of the UNIX epoch. 90728f6c2f2SEnji Cooper 90828f6c2f2SEnji Cooper##### elapsed_time {#UnitTest::elapsed_time} 90928f6c2f2SEnji Cooper 91028f6c2f2SEnji Cooper`TimeInMillis UnitTest::elapsed_time() const` 91128f6c2f2SEnji Cooper 91228f6c2f2SEnji CooperGets the elapsed time, in milliseconds. 91328f6c2f2SEnji Cooper 91428f6c2f2SEnji Cooper##### Passed {#UnitTest::Passed} 91528f6c2f2SEnji Cooper 91628f6c2f2SEnji Cooper`bool UnitTest::Passed() const` 91728f6c2f2SEnji Cooper 91828f6c2f2SEnji CooperReturns true if and only if the unit test passed (i.e. all test suites passed). 91928f6c2f2SEnji Cooper 92028f6c2f2SEnji Cooper##### Failed {#UnitTest::Failed} 92128f6c2f2SEnji Cooper 92228f6c2f2SEnji Cooper`bool UnitTest::Failed() const` 92328f6c2f2SEnji Cooper 92428f6c2f2SEnji CooperReturns true if and only if the unit test failed (i.e. some test suite failed or 92528f6c2f2SEnji Coopersomething outside of all tests failed). 92628f6c2f2SEnji Cooper 92728f6c2f2SEnji Cooper##### GetTestSuite {#UnitTest::GetTestSuite} 92828f6c2f2SEnji Cooper 92928f6c2f2SEnji Cooper`const TestSuite* UnitTest::GetTestSuite(int i) const` 93028f6c2f2SEnji Cooper 93128f6c2f2SEnji CooperGets the [`TestSuite`](#TestSuite) object for the `i`-th test suite among all 93228f6c2f2SEnji Cooperthe test suites. `i` can range from 0 to `total_test_suite_count() - 1`. If `i` 93328f6c2f2SEnji Cooperis not in that range, returns `NULL`. 93428f6c2f2SEnji Cooper 93528f6c2f2SEnji Cooper##### ad_hoc_test_result {#UnitTest::ad_hoc_test_result} 93628f6c2f2SEnji Cooper 93728f6c2f2SEnji Cooper`const TestResult& UnitTest::ad_hoc_test_result() const` 93828f6c2f2SEnji Cooper 93928f6c2f2SEnji CooperReturns the [`TestResult`](#TestResult) containing information on test failures 94028f6c2f2SEnji Cooperand properties logged outside of individual test suites. 94128f6c2f2SEnji Cooper 94228f6c2f2SEnji Cooper##### listeners {#UnitTest::listeners} 94328f6c2f2SEnji Cooper 94428f6c2f2SEnji Cooper`TestEventListeners& UnitTest::listeners()` 94528f6c2f2SEnji Cooper 94628f6c2f2SEnji CooperReturns the list of event listeners that can be used to track events inside 94728f6c2f2SEnji CooperGoogleTest. See [`TestEventListeners`](#TestEventListeners). 94828f6c2f2SEnji Cooper 94928f6c2f2SEnji Cooper### TestEventListener {#TestEventListener} 95028f6c2f2SEnji Cooper 95128f6c2f2SEnji Cooper`testing::TestEventListener` 95228f6c2f2SEnji Cooper 95328f6c2f2SEnji CooperThe interface for tracing execution of tests. The methods below are listed in 95428f6c2f2SEnji Cooperthe order the corresponding events are fired. 95528f6c2f2SEnji Cooper 95628f6c2f2SEnji Cooper#### Public Methods {#TestEventListener-public} 95728f6c2f2SEnji Cooper 95828f6c2f2SEnji Cooper##### OnTestProgramStart {#TestEventListener::OnTestProgramStart} 95928f6c2f2SEnji Cooper 96028f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestProgramStart(const UnitTest& unit_test)` 96128f6c2f2SEnji Cooper 96228f6c2f2SEnji CooperFired before any test activity starts. 96328f6c2f2SEnji Cooper 96428f6c2f2SEnji Cooper##### OnTestIterationStart {#TestEventListener::OnTestIterationStart} 96528f6c2f2SEnji Cooper 96628f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestIterationStart(const UnitTest& unit_test, 96728f6c2f2SEnji Cooperint iteration)` 96828f6c2f2SEnji Cooper 96928f6c2f2SEnji CooperFired before each iteration of tests starts. There may be more than one 97028f6c2f2SEnji Cooperiteration if `GTEST_FLAG(repeat)` is set. `iteration` is the iteration index, 97128f6c2f2SEnji Cooperstarting from 0. 97228f6c2f2SEnji Cooper 97328f6c2f2SEnji Cooper##### OnEnvironmentsSetUpStart {#TestEventListener::OnEnvironmentsSetUpStart} 97428f6c2f2SEnji Cooper 97528f6c2f2SEnji Cooper`virtual void TestEventListener::OnEnvironmentsSetUpStart(const UnitTest& 97628f6c2f2SEnji Cooperunit_test)` 97728f6c2f2SEnji Cooper 97828f6c2f2SEnji CooperFired before environment set-up for each iteration of tests starts. 97928f6c2f2SEnji Cooper 98028f6c2f2SEnji Cooper##### OnEnvironmentsSetUpEnd {#TestEventListener::OnEnvironmentsSetUpEnd} 98128f6c2f2SEnji Cooper 98228f6c2f2SEnji Cooper`virtual void TestEventListener::OnEnvironmentsSetUpEnd(const UnitTest& 98328f6c2f2SEnji Cooperunit_test)` 98428f6c2f2SEnji Cooper 98528f6c2f2SEnji CooperFired after environment set-up for each iteration of tests ends. 98628f6c2f2SEnji Cooper 98728f6c2f2SEnji Cooper##### OnTestSuiteStart {#TestEventListener::OnTestSuiteStart} 98828f6c2f2SEnji Cooper 98928f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestSuiteStart(const TestSuite& test_suite)` 99028f6c2f2SEnji Cooper 99128f6c2f2SEnji CooperFired before the test suite starts. 99228f6c2f2SEnji Cooper 99328f6c2f2SEnji Cooper##### OnTestStart {#TestEventListener::OnTestStart} 99428f6c2f2SEnji Cooper 99528f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestStart(const TestInfo& test_info)` 99628f6c2f2SEnji Cooper 99728f6c2f2SEnji CooperFired before the test starts. 99828f6c2f2SEnji Cooper 99928f6c2f2SEnji Cooper##### OnTestPartResult {#TestEventListener::OnTestPartResult} 100028f6c2f2SEnji Cooper 100128f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestPartResult(const TestPartResult& 100228f6c2f2SEnji Coopertest_part_result)` 100328f6c2f2SEnji Cooper 100428f6c2f2SEnji CooperFired after a failed assertion or a `SUCCEED()` invocation. If you want to throw 100528f6c2f2SEnji Cooperan exception from this function to skip to the next test, it must be an 100628f6c2f2SEnji Cooper[`AssertionException`](#AssertionException) or inherited from it. 100728f6c2f2SEnji Cooper 100828f6c2f2SEnji Cooper##### OnTestEnd {#TestEventListener::OnTestEnd} 100928f6c2f2SEnji Cooper 101028f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestEnd(const TestInfo& test_info)` 101128f6c2f2SEnji Cooper 101228f6c2f2SEnji CooperFired after the test ends. 101328f6c2f2SEnji Cooper 101428f6c2f2SEnji Cooper##### OnTestSuiteEnd {#TestEventListener::OnTestSuiteEnd} 101528f6c2f2SEnji Cooper 101628f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestSuiteEnd(const TestSuite& test_suite)` 101728f6c2f2SEnji Cooper 101828f6c2f2SEnji CooperFired after the test suite ends. 101928f6c2f2SEnji Cooper 102028f6c2f2SEnji Cooper##### OnEnvironmentsTearDownStart {#TestEventListener::OnEnvironmentsTearDownStart} 102128f6c2f2SEnji Cooper 102228f6c2f2SEnji Cooper`virtual void TestEventListener::OnEnvironmentsTearDownStart(const UnitTest& 102328f6c2f2SEnji Cooperunit_test)` 102428f6c2f2SEnji Cooper 102528f6c2f2SEnji CooperFired before environment tear-down for each iteration of tests starts. 102628f6c2f2SEnji Cooper 102728f6c2f2SEnji Cooper##### OnEnvironmentsTearDownEnd {#TestEventListener::OnEnvironmentsTearDownEnd} 102828f6c2f2SEnji Cooper 102928f6c2f2SEnji Cooper`virtual void TestEventListener::OnEnvironmentsTearDownEnd(const UnitTest& 103028f6c2f2SEnji Cooperunit_test)` 103128f6c2f2SEnji Cooper 103228f6c2f2SEnji CooperFired after environment tear-down for each iteration of tests ends. 103328f6c2f2SEnji Cooper 103428f6c2f2SEnji Cooper##### OnTestIterationEnd {#TestEventListener::OnTestIterationEnd} 103528f6c2f2SEnji Cooper 103628f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestIterationEnd(const UnitTest& unit_test, 103728f6c2f2SEnji Cooperint iteration)` 103828f6c2f2SEnji Cooper 103928f6c2f2SEnji CooperFired after each iteration of tests finishes. 104028f6c2f2SEnji Cooper 104128f6c2f2SEnji Cooper##### OnTestProgramEnd {#TestEventListener::OnTestProgramEnd} 104228f6c2f2SEnji Cooper 104328f6c2f2SEnji Cooper`virtual void TestEventListener::OnTestProgramEnd(const UnitTest& unit_test)` 104428f6c2f2SEnji Cooper 104528f6c2f2SEnji CooperFired after all test activities have ended. 104628f6c2f2SEnji Cooper 104728f6c2f2SEnji Cooper### TestEventListeners {#TestEventListeners} 104828f6c2f2SEnji Cooper 104928f6c2f2SEnji Cooper`testing::TestEventListeners` 105028f6c2f2SEnji Cooper 105128f6c2f2SEnji CooperLets users add listeners to track events in GoogleTest. 105228f6c2f2SEnji Cooper 105328f6c2f2SEnji Cooper#### Public Methods {#TestEventListeners-public} 105428f6c2f2SEnji Cooper 105528f6c2f2SEnji Cooper##### Append {#TestEventListeners::Append} 105628f6c2f2SEnji Cooper 105728f6c2f2SEnji Cooper`void TestEventListeners::Append(TestEventListener* listener)` 105828f6c2f2SEnji Cooper 105928f6c2f2SEnji CooperAppends an event listener to the end of the list. GoogleTest assumes ownership 106028f6c2f2SEnji Cooperof the listener (i.e. it will delete the listener when the test program 106128f6c2f2SEnji Cooperfinishes). 106228f6c2f2SEnji Cooper 106328f6c2f2SEnji Cooper##### Release {#TestEventListeners::Release} 106428f6c2f2SEnji Cooper 106528f6c2f2SEnji Cooper`TestEventListener* TestEventListeners::Release(TestEventListener* listener)` 106628f6c2f2SEnji Cooper 106728f6c2f2SEnji CooperRemoves the given event listener from the list and returns it. It then becomes 106828f6c2f2SEnji Cooperthe caller's responsibility to delete the listener. Returns `NULL` if the 106928f6c2f2SEnji Cooperlistener is not found in the list. 107028f6c2f2SEnji Cooper 107128f6c2f2SEnji Cooper##### default_result_printer {#TestEventListeners::default_result_printer} 107228f6c2f2SEnji Cooper 107328f6c2f2SEnji Cooper`TestEventListener* TestEventListeners::default_result_printer() const` 107428f6c2f2SEnji Cooper 107528f6c2f2SEnji CooperReturns the standard listener responsible for the default console output. Can be 107628f6c2f2SEnji Cooperremoved from the listeners list to shut down default console output. Note that 107728f6c2f2SEnji Cooperremoving this object from the listener list with 107828f6c2f2SEnji Cooper[`Release()`](#TestEventListeners::Release) transfers its ownership to the 107928f6c2f2SEnji Coopercaller and makes this function return `NULL` the next time. 108028f6c2f2SEnji Cooper 108128f6c2f2SEnji Cooper##### default_xml_generator {#TestEventListeners::default_xml_generator} 108228f6c2f2SEnji Cooper 108328f6c2f2SEnji Cooper`TestEventListener* TestEventListeners::default_xml_generator() const` 108428f6c2f2SEnji Cooper 108528f6c2f2SEnji CooperReturns the standard listener responsible for the default XML output controlled 108628f6c2f2SEnji Cooperby the `--gtest_output=xml` flag. Can be removed from the listeners list by 108728f6c2f2SEnji Cooperusers who want to shut down the default XML output controlled by this flag and 108828f6c2f2SEnji Coopersubstitute it with custom one. Note that removing this object from the listener 108928f6c2f2SEnji Cooperlist with [`Release()`](#TestEventListeners::Release) transfers its ownership to 109028f6c2f2SEnji Cooperthe caller and makes this function return `NULL` the next time. 109128f6c2f2SEnji Cooper 109228f6c2f2SEnji Cooper### TestPartResult {#TestPartResult} 109328f6c2f2SEnji Cooper 109428f6c2f2SEnji Cooper`testing::TestPartResult` 109528f6c2f2SEnji Cooper 109628f6c2f2SEnji CooperA copyable object representing the result of a test part (i.e. an assertion or 109728f6c2f2SEnji Cooperan explicit `FAIL()`, `ADD_FAILURE()`, or `SUCCESS()`). 109828f6c2f2SEnji Cooper 109928f6c2f2SEnji Cooper#### Public Methods {#TestPartResult-public} 110028f6c2f2SEnji Cooper 110128f6c2f2SEnji Cooper##### type {#TestPartResult::type} 110228f6c2f2SEnji Cooper 110328f6c2f2SEnji Cooper`Type TestPartResult::type() const` 110428f6c2f2SEnji Cooper 110528f6c2f2SEnji CooperGets the outcome of the test part. 110628f6c2f2SEnji Cooper 110728f6c2f2SEnji CooperThe return type `Type` is an enum defined as follows: 110828f6c2f2SEnji Cooper 110928f6c2f2SEnji Cooper```cpp 111028f6c2f2SEnji Cooperenum Type { 111128f6c2f2SEnji Cooper kSuccess, // Succeeded. 111228f6c2f2SEnji Cooper kNonFatalFailure, // Failed but the test can continue. 111328f6c2f2SEnji Cooper kFatalFailure, // Failed and the test should be terminated. 111428f6c2f2SEnji Cooper kSkip // Skipped. 111528f6c2f2SEnji Cooper}; 111628f6c2f2SEnji Cooper``` 111728f6c2f2SEnji Cooper 111828f6c2f2SEnji Cooper##### file_name {#TestPartResult::file_name} 111928f6c2f2SEnji Cooper 112028f6c2f2SEnji Cooper`const char* TestPartResult::file_name() const` 112128f6c2f2SEnji Cooper 112228f6c2f2SEnji CooperGets the name of the source file where the test part took place, or `NULL` if 112328f6c2f2SEnji Cooperit's unknown. 112428f6c2f2SEnji Cooper 112528f6c2f2SEnji Cooper##### line_number {#TestPartResult::line_number} 112628f6c2f2SEnji Cooper 112728f6c2f2SEnji Cooper`int TestPartResult::line_number() const` 112828f6c2f2SEnji Cooper 112928f6c2f2SEnji CooperGets the line in the source file where the test part took place, or `-1` if it's 113028f6c2f2SEnji Cooperunknown. 113128f6c2f2SEnji Cooper 113228f6c2f2SEnji Cooper##### summary {#TestPartResult::summary} 113328f6c2f2SEnji Cooper 113428f6c2f2SEnji Cooper`const char* TestPartResult::summary() const` 113528f6c2f2SEnji Cooper 113628f6c2f2SEnji CooperGets the summary of the failure message. 113728f6c2f2SEnji Cooper 113828f6c2f2SEnji Cooper##### message {#TestPartResult::message} 113928f6c2f2SEnji Cooper 114028f6c2f2SEnji Cooper`const char* TestPartResult::message() const` 114128f6c2f2SEnji Cooper 114228f6c2f2SEnji CooperGets the message associated with the test part. 114328f6c2f2SEnji Cooper 114428f6c2f2SEnji Cooper##### skipped {#TestPartResult::skipped} 114528f6c2f2SEnji Cooper 114628f6c2f2SEnji Cooper`bool TestPartResult::skipped() const` 114728f6c2f2SEnji Cooper 114828f6c2f2SEnji CooperReturns true if and only if the test part was skipped. 114928f6c2f2SEnji Cooper 115028f6c2f2SEnji Cooper##### passed {#TestPartResult::passed} 115128f6c2f2SEnji Cooper 115228f6c2f2SEnji Cooper`bool TestPartResult::passed() const` 115328f6c2f2SEnji Cooper 115428f6c2f2SEnji CooperReturns true if and only if the test part passed. 115528f6c2f2SEnji Cooper 115628f6c2f2SEnji Cooper##### nonfatally_failed {#TestPartResult::nonfatally_failed} 115728f6c2f2SEnji Cooper 115828f6c2f2SEnji Cooper`bool TestPartResult::nonfatally_failed() const` 115928f6c2f2SEnji Cooper 116028f6c2f2SEnji CooperReturns true if and only if the test part non-fatally failed. 116128f6c2f2SEnji Cooper 116228f6c2f2SEnji Cooper##### fatally_failed {#TestPartResult::fatally_failed} 116328f6c2f2SEnji Cooper 116428f6c2f2SEnji Cooper`bool TestPartResult::fatally_failed() const` 116528f6c2f2SEnji Cooper 116628f6c2f2SEnji CooperReturns true if and only if the test part fatally failed. 116728f6c2f2SEnji Cooper 116828f6c2f2SEnji Cooper##### failed {#TestPartResult::failed} 116928f6c2f2SEnji Cooper 117028f6c2f2SEnji Cooper`bool TestPartResult::failed() const` 117128f6c2f2SEnji Cooper 117228f6c2f2SEnji CooperReturns true if and only if the test part failed. 117328f6c2f2SEnji Cooper 117428f6c2f2SEnji Cooper### TestProperty {#TestProperty} 117528f6c2f2SEnji Cooper 117628f6c2f2SEnji Cooper`testing::TestProperty` 117728f6c2f2SEnji Cooper 117828f6c2f2SEnji CooperA copyable object representing a user-specified test property which can be 117928f6c2f2SEnji Cooperoutput as a key/value string pair. 118028f6c2f2SEnji Cooper 118128f6c2f2SEnji Cooper#### Public Methods {#TestProperty-public} 118228f6c2f2SEnji Cooper 118328f6c2f2SEnji Cooper##### key {#key} 118428f6c2f2SEnji Cooper 118528f6c2f2SEnji Cooper`const char* key() const` 118628f6c2f2SEnji Cooper 118728f6c2f2SEnji CooperGets the user-supplied key. 118828f6c2f2SEnji Cooper 118928f6c2f2SEnji Cooper##### value {#value} 119028f6c2f2SEnji Cooper 119128f6c2f2SEnji Cooper`const char* value() const` 119228f6c2f2SEnji Cooper 119328f6c2f2SEnji CooperGets the user-supplied value. 119428f6c2f2SEnji Cooper 119528f6c2f2SEnji Cooper##### SetValue {#SetValue} 119628f6c2f2SEnji Cooper 119728f6c2f2SEnji Cooper`void SetValue(const std::string& new_value)` 119828f6c2f2SEnji Cooper 119928f6c2f2SEnji CooperSets a new value, overriding the previous one. 120028f6c2f2SEnji Cooper 120128f6c2f2SEnji Cooper### TestResult {#TestResult} 120228f6c2f2SEnji Cooper 120328f6c2f2SEnji Cooper`testing::TestResult` 120428f6c2f2SEnji Cooper 120528f6c2f2SEnji CooperContains information about the result of a single test. 120628f6c2f2SEnji Cooper 120728f6c2f2SEnji Cooper`TestResult` is not copyable. 120828f6c2f2SEnji Cooper 120928f6c2f2SEnji Cooper#### Public Methods {#TestResult-public} 121028f6c2f2SEnji Cooper 121128f6c2f2SEnji Cooper##### total_part_count {#TestResult::total_part_count} 121228f6c2f2SEnji Cooper 121328f6c2f2SEnji Cooper`int TestResult::total_part_count() const` 121428f6c2f2SEnji Cooper 121528f6c2f2SEnji CooperGets the number of all test parts. This is the sum of the number of successful 121628f6c2f2SEnji Coopertest parts and the number of failed test parts. 121728f6c2f2SEnji Cooper 121828f6c2f2SEnji Cooper##### test_property_count {#TestResult::test_property_count} 121928f6c2f2SEnji Cooper 122028f6c2f2SEnji Cooper`int TestResult::test_property_count() const` 122128f6c2f2SEnji Cooper 122228f6c2f2SEnji CooperReturns the number of test properties. 122328f6c2f2SEnji Cooper 122428f6c2f2SEnji Cooper##### Passed {#TestResult::Passed} 122528f6c2f2SEnji Cooper 122628f6c2f2SEnji Cooper`bool TestResult::Passed() const` 122728f6c2f2SEnji Cooper 122828f6c2f2SEnji CooperReturns true if and only if the test passed (i.e. no test part failed). 122928f6c2f2SEnji Cooper 123028f6c2f2SEnji Cooper##### Skipped {#TestResult::Skipped} 123128f6c2f2SEnji Cooper 123228f6c2f2SEnji Cooper`bool TestResult::Skipped() const` 123328f6c2f2SEnji Cooper 123428f6c2f2SEnji CooperReturns true if and only if the test was skipped. 123528f6c2f2SEnji Cooper 123628f6c2f2SEnji Cooper##### Failed {#TestResult::Failed} 123728f6c2f2SEnji Cooper 123828f6c2f2SEnji Cooper`bool TestResult::Failed() const` 123928f6c2f2SEnji Cooper 124028f6c2f2SEnji CooperReturns true if and only if the test failed. 124128f6c2f2SEnji Cooper 124228f6c2f2SEnji Cooper##### HasFatalFailure {#TestResult::HasFatalFailure} 124328f6c2f2SEnji Cooper 124428f6c2f2SEnji Cooper`bool TestResult::HasFatalFailure() const` 124528f6c2f2SEnji Cooper 124628f6c2f2SEnji CooperReturns true if and only if the test fatally failed. 124728f6c2f2SEnji Cooper 124828f6c2f2SEnji Cooper##### HasNonfatalFailure {#TestResult::HasNonfatalFailure} 124928f6c2f2SEnji Cooper 125028f6c2f2SEnji Cooper`bool TestResult::HasNonfatalFailure() const` 125128f6c2f2SEnji Cooper 125228f6c2f2SEnji CooperReturns true if and only if the test has a non-fatal failure. 125328f6c2f2SEnji Cooper 125428f6c2f2SEnji Cooper##### elapsed_time {#TestResult::elapsed_time} 125528f6c2f2SEnji Cooper 125628f6c2f2SEnji Cooper`TimeInMillis TestResult::elapsed_time() const` 125728f6c2f2SEnji Cooper 125828f6c2f2SEnji CooperReturns the elapsed time, in milliseconds. 125928f6c2f2SEnji Cooper 126028f6c2f2SEnji Cooper##### start_timestamp {#TestResult::start_timestamp} 126128f6c2f2SEnji Cooper 126228f6c2f2SEnji Cooper`TimeInMillis TestResult::start_timestamp() const` 126328f6c2f2SEnji Cooper 126428f6c2f2SEnji CooperGets the time of the test case start, in ms from the start of the UNIX epoch. 126528f6c2f2SEnji Cooper 126628f6c2f2SEnji Cooper##### GetTestPartResult {#TestResult::GetTestPartResult} 126728f6c2f2SEnji Cooper 126828f6c2f2SEnji Cooper`const TestPartResult& TestResult::GetTestPartResult(int i) const` 126928f6c2f2SEnji Cooper 127028f6c2f2SEnji CooperReturns the [`TestPartResult`](#TestPartResult) for the `i`-th test part result 127128f6c2f2SEnji Cooperamong all the results. `i` can range from 0 to `total_part_count() - 1`. If `i` 127228f6c2f2SEnji Cooperis not in that range, aborts the program. 127328f6c2f2SEnji Cooper 127428f6c2f2SEnji Cooper##### GetTestProperty {#TestResult::GetTestProperty} 127528f6c2f2SEnji Cooper 127628f6c2f2SEnji Cooper`const TestProperty& TestResult::GetTestProperty(int i) const` 127728f6c2f2SEnji Cooper 127828f6c2f2SEnji CooperReturns the [`TestProperty`](#TestProperty) object for the `i`-th test property. 127928f6c2f2SEnji Cooper`i` can range from 0 to `test_property_count() - 1`. If `i` is not in that 128028f6c2f2SEnji Cooperrange, aborts the program. 128128f6c2f2SEnji Cooper 128228f6c2f2SEnji Cooper### TimeInMillis {#TimeInMillis} 128328f6c2f2SEnji Cooper 128428f6c2f2SEnji Cooper`testing::TimeInMillis` 128528f6c2f2SEnji Cooper 128628f6c2f2SEnji CooperAn integer type representing time in milliseconds. 128728f6c2f2SEnji Cooper 128828f6c2f2SEnji Cooper### Types {#Types} 128928f6c2f2SEnji Cooper 129028f6c2f2SEnji Cooper`testing::Types<T...>` 129128f6c2f2SEnji Cooper 129228f6c2f2SEnji CooperRepresents a list of types for use in typed tests and type-parameterized tests. 129328f6c2f2SEnji Cooper 129428f6c2f2SEnji CooperThe template argument `T...` can be any number of types, for example: 129528f6c2f2SEnji Cooper 129628f6c2f2SEnji Cooper``` 129728f6c2f2SEnji Coopertesting::Types<char, int, unsigned int> 129828f6c2f2SEnji Cooper``` 129928f6c2f2SEnji Cooper 130028f6c2f2SEnji CooperSee [Typed Tests](../advanced.md#typed-tests) and 130128f6c2f2SEnji Cooper[Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more 130228f6c2f2SEnji Cooperinformation. 130328f6c2f2SEnji Cooper 130428f6c2f2SEnji Cooper### WithParamInterface {#WithParamInterface} 130528f6c2f2SEnji Cooper 130628f6c2f2SEnji Cooper`testing::WithParamInterface<T>` 130728f6c2f2SEnji Cooper 130828f6c2f2SEnji CooperThe pure interface class that all value-parameterized tests inherit from. 130928f6c2f2SEnji Cooper 131028f6c2f2SEnji CooperA value-parameterized test fixture class must inherit from both [`Test`](#Test) 131128f6c2f2SEnji Cooperand `WithParamInterface`. In most cases that just means inheriting from 131228f6c2f2SEnji Cooper[`TestWithParam`](#TestWithParam), but more complicated test hierarchies may 131328f6c2f2SEnji Cooperneed to inherit from `Test` and `WithParamInterface` at different levels. 131428f6c2f2SEnji Cooper 131528f6c2f2SEnji CooperThis interface defines the type alias `ParamType` for the parameter type `T` and 131628f6c2f2SEnji Cooperhas support for accessing the test parameter value via the `GetParam()` method: 131728f6c2f2SEnji Cooper 131828f6c2f2SEnji Cooper``` 131928f6c2f2SEnji Cooperstatic const ParamType& GetParam() 132028f6c2f2SEnji Cooper``` 132128f6c2f2SEnji Cooper 132228f6c2f2SEnji CooperFor more information, see 132328f6c2f2SEnji Cooper[Value-Parameterized Tests](../advanced.md#value-parameterized-tests). 132428f6c2f2SEnji Cooper 132528f6c2f2SEnji Cooper## Functions 132628f6c2f2SEnji Cooper 132728f6c2f2SEnji CooperGoogleTest defines the following functions to help with writing and running 132828f6c2f2SEnji Coopertests. 132928f6c2f2SEnji Cooper 133028f6c2f2SEnji Cooper### InitGoogleTest {#InitGoogleTest} 133128f6c2f2SEnji Cooper 133228f6c2f2SEnji Cooper`void testing::InitGoogleTest(int* argc, char** argv)` \ 133328f6c2f2SEnji Cooper`void testing::InitGoogleTest(int* argc, wchar_t** argv)` \ 133428f6c2f2SEnji Cooper`void testing::InitGoogleTest()` 133528f6c2f2SEnji Cooper 133628f6c2f2SEnji CooperInitializes GoogleTest. This must be called before calling 133728f6c2f2SEnji Cooper[`RUN_ALL_TESTS()`](#RUN_ALL_TESTS). In particular, it parses the command line 133828f6c2f2SEnji Cooperfor the flags that GoogleTest recognizes. Whenever a GoogleTest flag is seen, it 1339*5ca8c28cSEnji Cooperis removed from `argv`, and `*argc` is decremented. Keep in mind that `argv` 1340*5ca8c28cSEnji Coopermust terminate with a `NULL` pointer (i.e. `argv[argc]` is `NULL`), which is 1341*5ca8c28cSEnji Cooperalready the case with the default `argv` passed to `main`. 134228f6c2f2SEnji Cooper 134328f6c2f2SEnji CooperNo value is returned. Instead, the GoogleTest flag variables are updated. 134428f6c2f2SEnji Cooper 134528f6c2f2SEnji CooperThe `InitGoogleTest(int* argc, wchar_t** argv)` overload can be used in Windows 134628f6c2f2SEnji Cooperprograms compiled in `UNICODE` mode. 134728f6c2f2SEnji Cooper 134828f6c2f2SEnji CooperThe argument-less `InitGoogleTest()` overload can be used on Arduino/embedded 134928f6c2f2SEnji Cooperplatforms where there is no `argc`/`argv`. 135028f6c2f2SEnji Cooper 135128f6c2f2SEnji Cooper### AddGlobalTestEnvironment {#AddGlobalTestEnvironment} 135228f6c2f2SEnji Cooper 135328f6c2f2SEnji Cooper`Environment* testing::AddGlobalTestEnvironment(Environment* env)` 135428f6c2f2SEnji Cooper 135528f6c2f2SEnji CooperAdds a test environment to the test program. Must be called before 135628f6c2f2SEnji Cooper[`RUN_ALL_TESTS()`](#RUN_ALL_TESTS) is called. See 135728f6c2f2SEnji Cooper[Global Set-Up and Tear-Down](../advanced.md#global-set-up-and-tear-down) for 135828f6c2f2SEnji Coopermore information. 135928f6c2f2SEnji Cooper 136028f6c2f2SEnji CooperSee also [`Environment`](#Environment). 136128f6c2f2SEnji Cooper 136228f6c2f2SEnji Cooper### RegisterTest {#RegisterTest} 136328f6c2f2SEnji Cooper 136428f6c2f2SEnji Cooper```cpp 136528f6c2f2SEnji Coopertemplate <typename Factory> 136628f6c2f2SEnji CooperTestInfo* testing::RegisterTest(const char* test_suite_name, const char* test_name, 136728f6c2f2SEnji Cooper const char* type_param, const char* value_param, 136828f6c2f2SEnji Cooper const char* file, int line, Factory factory) 136928f6c2f2SEnji Cooper``` 137028f6c2f2SEnji Cooper 137128f6c2f2SEnji CooperDynamically registers a test with the framework. 137228f6c2f2SEnji Cooper 137328f6c2f2SEnji CooperThe `factory` argument is a factory callable (move-constructible) object or 137428f6c2f2SEnji Cooperfunction pointer that creates a new instance of the `Test` object. It handles 137528f6c2f2SEnji Cooperownership to the caller. The signature of the callable is `Fixture*()`, where 137628f6c2f2SEnji Cooper`Fixture` is the test fixture class for the test. All tests registered with the 137728f6c2f2SEnji Coopersame `test_suite_name` must return the same fixture type. This is checked at 137828f6c2f2SEnji Cooperruntime. 137928f6c2f2SEnji Cooper 138028f6c2f2SEnji CooperThe framework will infer the fixture class from the factory and will call the 138128f6c2f2SEnji Cooper`SetUpTestSuite` and `TearDownTestSuite` methods for it. 138228f6c2f2SEnji Cooper 138328f6c2f2SEnji CooperMust be called before [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS) is invoked, otherwise 138428f6c2f2SEnji Cooperbehavior is undefined. 138528f6c2f2SEnji Cooper 138628f6c2f2SEnji CooperSee 138728f6c2f2SEnji Cooper[Registering tests programmatically](../advanced.md#registering-tests-programmatically) 138828f6c2f2SEnji Cooperfor more information. 138928f6c2f2SEnji Cooper 139028f6c2f2SEnji Cooper### RUN_ALL_TESTS {#RUN_ALL_TESTS} 139128f6c2f2SEnji Cooper 139228f6c2f2SEnji Cooper`int RUN_ALL_TESTS()` 139328f6c2f2SEnji Cooper 139428f6c2f2SEnji CooperUse this function in `main()` to run all tests. It returns `0` if all tests are 139528f6c2f2SEnji Coopersuccessful, or `1` otherwise. 139628f6c2f2SEnji Cooper 139728f6c2f2SEnji Cooper`RUN_ALL_TESTS()` should be invoked after the command line has been parsed by 139828f6c2f2SEnji Cooper[`InitGoogleTest()`](#InitGoogleTest). 139928f6c2f2SEnji Cooper 140028f6c2f2SEnji CooperThis function was formerly a macro; thus, it is in the global namespace and has 140128f6c2f2SEnji Cooperan all-caps name. 140228f6c2f2SEnji Cooper 140328f6c2f2SEnji Cooper### AssertionSuccess {#AssertionSuccess} 140428f6c2f2SEnji Cooper 140528f6c2f2SEnji Cooper`AssertionResult testing::AssertionSuccess()` 140628f6c2f2SEnji Cooper 140728f6c2f2SEnji CooperCreates a successful assertion result. See 140828f6c2f2SEnji Cooper[`AssertionResult`](#AssertionResult). 140928f6c2f2SEnji Cooper 141028f6c2f2SEnji Cooper### AssertionFailure {#AssertionFailure} 141128f6c2f2SEnji Cooper 141228f6c2f2SEnji Cooper`AssertionResult testing::AssertionFailure()` 141328f6c2f2SEnji Cooper 141428f6c2f2SEnji CooperCreates a failed assertion result. Use the `<<` operator to store a failure 141528f6c2f2SEnji Coopermessage: 141628f6c2f2SEnji Cooper 141728f6c2f2SEnji Cooper```cpp 141828f6c2f2SEnji Coopertesting::AssertionFailure() << "My failure message"; 141928f6c2f2SEnji Cooper``` 142028f6c2f2SEnji Cooper 142128f6c2f2SEnji CooperSee [`AssertionResult`](#AssertionResult). 142228f6c2f2SEnji Cooper 142328f6c2f2SEnji Cooper### StaticAssertTypeEq {#StaticAssertTypeEq} 142428f6c2f2SEnji Cooper 142528f6c2f2SEnji Cooper`testing::StaticAssertTypeEq<T1, T2>()` 142628f6c2f2SEnji Cooper 142728f6c2f2SEnji CooperCompile-time assertion for type equality. Compiles if and only if `T1` and `T2` 142828f6c2f2SEnji Cooperare the same type. The value it returns is irrelevant. 142928f6c2f2SEnji Cooper 143028f6c2f2SEnji CooperSee [Type Assertions](../advanced.md#type-assertions) for more information. 143128f6c2f2SEnji Cooper 143228f6c2f2SEnji Cooper### PrintToString {#PrintToString} 143328f6c2f2SEnji Cooper 143428f6c2f2SEnji Cooper`std::string testing::PrintToString(x)` 143528f6c2f2SEnji Cooper 143628f6c2f2SEnji CooperPrints any value `x` using GoogleTest's value printer. 143728f6c2f2SEnji Cooper 143828f6c2f2SEnji CooperSee 143928f6c2f2SEnji Cooper[Teaching GoogleTest How to Print Your Values](../advanced.md#teaching-googletest-how-to-print-your-values) 144028f6c2f2SEnji Cooperfor more information. 144128f6c2f2SEnji Cooper 144228f6c2f2SEnji Cooper### PrintToStringParamName {#PrintToStringParamName} 144328f6c2f2SEnji Cooper 144428f6c2f2SEnji Cooper`std::string testing::PrintToStringParamName(TestParamInfo<T>& info)` 144528f6c2f2SEnji Cooper 144628f6c2f2SEnji CooperA built-in parameterized test name generator which returns the result of 144728f6c2f2SEnji Cooper[`PrintToString`](#PrintToString) called on `info.param`. Does not work when the 144828f6c2f2SEnji Coopertest parameter is a `std::string` or C string. See 144928f6c2f2SEnji Cooper[Specifying Names for Value-Parameterized Test Parameters](../advanced.md#specifying-names-for-value-parameterized-test-parameters) 145028f6c2f2SEnji Cooperfor more information. 145128f6c2f2SEnji Cooper 145228f6c2f2SEnji CooperSee also [`TestParamInfo`](#TestParamInfo) and 145328f6c2f2SEnji Cooper[`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P). 1454