Debian Codegraph @

src/external/googletest/docs/reference/testing.md

raw
1 # Testing Reference
2
3 <!--* toc_depth: 3 *-->
4
5 This page lists the facilities provided by GoogleTest for writing test programs.
6 To use them, add `#include <gtest/gtest.h>`.
7
8 ## Macros
9
10 GoogleTest defines the following macros for writing tests.
11
12 ### TEST {#TEST}
13
14 <pre>
15 TEST(<em>TestSuiteName</em>, <em>TestName</em>) {
16 ... <em>statements</em> ...
17 }
18 </pre>
19
20 Defines an individual test named *`TestName`* in the test suite
21 *`TestSuiteName`*, consisting of the given statements.
22
23 Both arguments *`TestSuiteName`* and *`TestName`* must be valid C++ identifiers
24 and must not contain underscores (`_`). Tests in different test suites can have
25 the same individual name.
26
27 The statements within the test body can be any code under test.
28 [Assertions](assertions.md) used within the test body determine the outcome of
29 the test.
30
31 ### TEST_F {#TEST_F}
32
33 <pre>
34 TEST_F(<em>TestFixtureName</em>, <em>TestName</em>) {
35 ... <em>statements</em> ...
36 }
37 </pre>
38
39 Defines an individual test named *`TestName`* that uses the test fixture class
40 *`TestFixtureName`*. The test suite name is *`TestFixtureName`*.
41
42 Both arguments *`TestFixtureName`* and *`TestName`* must be valid C++
43 identifiers and must not contain underscores (`_`). *`TestFixtureName`* must be
44 the name of a test fixture class—see
45 [Test Fixtures](../primer.md#same-data-multiple-tests).
46
47 The statements within the test body can be any code under test.
48 [Assertions](assertions.md) used within the test body determine the outcome of
49 the test.
50
51 ### TEST_P {#TEST_P}
52
53 <pre>
54 TEST_P(<em>TestFixtureName</em>, <em>TestName</em>) {
55 ... <em>statements</em> ...
56 }
57 </pre>
58
59 Defines an individual value-parameterized test named *`TestName`* that uses the
60 test fixture class *`TestFixtureName`*. The test suite name is
61 *`TestFixtureName`*.
62
63 Both arguments *`TestFixtureName`* and *`TestName`* must be valid C++
64 identifiers and must not contain underscores (`_`). *`TestFixtureName`* must be
65 the name of a value-parameterized test fixture class—see
66 [Value-Parameterized Tests](../advanced.md#value-parameterized-tests).
67
68 The statements within the test body can be any code under test. Within the test
69 body, the test parameter can be accessed with the `GetParam()` function (see
70 [`WithParamInterface`](#WithParamInterface)). For example:
71
72 ```cpp
73 TEST_P(MyTestSuite, DoesSomething) {
74 ...
75 EXPECT_TRUE(DoSomething(GetParam()));
76 ...
77 }
78 ```
79
80 [Assertions](assertions.md) used within the test body determine the outcome of
81 the test.
82
83 See also [`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P).
84
85 ### INSTANTIATE_TEST_SUITE_P {#INSTANTIATE_TEST_SUITE_P}
86
87 `INSTANTIATE_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`param_generator`*`)`
88 \
89 `INSTANTIATE_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`param_generator`*`,`*`name_generator`*`)`
90
91 Instantiates the value-parameterized test suite *`TestSuiteName`* (defined with
92 [`TEST_P`](#TEST_P)).
93
94 The argument *`InstantiationName`* is a unique name for the instantiation of the
95 test suite, to distinguish between multiple instantiations. In test output, the
96 instantiation name is added as a prefix to the test suite name
97 *`TestSuiteName`*. If *`InstantiationName`* is empty
98 (`INSTANTIATE_TEST_SUITE_P(, ...)`), no prefix is added.
99
100 The argument *`param_generator`* is one of the following GoogleTest-provided
101 functions that generate the test parameters, all defined in the `::testing`
102 namespace:
103
104 <span id="param-generators"></span>
105
106 | Parameter Generator | Behavior |
107 | ------------------- | ---------------------------------------------------- |
108 | `Range(begin, end [, step])` | Yields values `{begin, begin+step, begin+step+step, ...}`. The values do not include `end`. `step` defaults to 1. |
109 | `Values(v1, v2, ..., vN)` | Yields values `{v1, v2, ..., vN}`. |
110 | `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. |
111 | `Bool()` | Yields sequence `{false, true}`. |
112 | `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`. |
113 | `ConvertGenerator<T>(g)` or `ConvertGenerator(g, func)` | Yields values generated by generator `g`, `static_cast` from `T`. (Note: `T` might not be what you expect. See [*Using ConvertGenerator*](#using-convertgenerator) below.) The second overload uses `func` to perform the conversion. |
114
115 The optional last argument *`name_generator`* is a function or functor that
116 generates custom test name suffixes based on the test parameters. The function
117 must accept an argument of type
118 [`TestParamInfo<class ParamType>`](#TestParamInfo) and return a `std::string`.
119 The test name suffix can only contain alphanumeric characters and underscores.
120 GoogleTest provides [`PrintToStringParamName`](#PrintToStringParamName), or a
121 custom function can be used for more control:
122
123 ```cpp
124 INSTANTIATE_TEST_SUITE_P(
125 MyInstantiation, MyTestSuite,
126 testing::Values(...),
127 [](const testing::TestParamInfo<MyTestSuite::ParamType>& info) {
128 // Can use info.param here to generate the test suffix
129 std::string name = ...
130 return name;
131 });
132 ```
133
134 For more information, see
135 [Value-Parameterized Tests](../advanced.md#value-parameterized-tests).
136
137 See also
138 [`GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST`](#GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST).
139
140 ###### Using `ConvertGenerator`
141
142 The functions listed in the table above appear to return generators that create
143 values of the desired types, but this is not generally the case. Rather, they
144 typically return factory objects that convert to the the desired generators.
145 This affords some flexibility in allowing you to specify values of types that
146 are different from, yet implicitly convertible to, the actual parameter type
147 required by your fixture class.
148
149 For example, you can do the following with a fixture that requires an `int`
150 parameter:
151
152 ```cpp
153 INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite,
154 testing::Values(1, 1.2)); // Yes, Values() supports heterogeneous argument types.
155 ```
156
157 It might seem obvious that `1.2` &mdash; a `double` &mdash; will be converted to
158 an `int` but in actuality it requires some template gymnastics involving the
159 indirection described in the previous paragraph.
160
161 What if your parameter type is not implicitly convertible from the generated
162 type but is *explicitly* convertible? There will be no automatic conversion, but
163 you can force it by applying `ConvertGenerator<T>`. The compiler can
164 automatically deduce the target type (your fixture's parameter type), but
165 because of the aforementioned indirection it cannot decide what the generated
166 type should be. You need to tell it, by providing the type `T` explicitly. Thus
167 `T` should not be your fixture's parameter type, but rather an intermediate type
168 that is supported by the factory object, and which can be `static_cast` to the
169 fixture's parameter type:
170
171 ```cpp
172 // The fixture's parameter type.
173 class MyParam {
174 public:
175 // Explicit converting ctor.
176 explicit MyParam(const std::tuple<int, bool>& t);
177 ...
178 };
179
180 INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite,
181 ConvertGenerator<std::tuple<int, bool>>(Combine(Values(0.1, 1.2), Bool())));
182 ```
183
184 In this example `Combine` supports the generation of `std::tuple<int, bool>>`
185 objects (even though the provided values for the first tuple element are
186 `double`s) and those `tuple`s get converted into `MyParam` objects by virtue of
187 the call to `ConvertGenerator`.
188
189 For parameter types that are not convertible from the generated types you can
190 provide a callable that does the conversion. The callable accepts an object of
191 the generated type and returns an object of the fixture's parameter type. The
192 generated type can often be deduced by the compiler from the callable's call
193 signature so you do not usually need specify it explicitly (but see a caveat
194 below).
195
196 ```cpp
197 // The fixture's parameter type.
198 class MyParam {
199 public:
200 MyParam(int, bool);
201 ...
202 };
203
204 INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite,
205 ConvertGenerator(Combine(Values(1, 1.2), Bool()),
206 [](const std::tuple<int i, bool>& t){
207 const auto [i, b] = t;
208 return MyParam(i, b);
209 }));
210 ```
211
212 The callable may be anything that can be used to initialize a `std::function`
213 with the appropriate call signature. Note the callable's return object gets
214 `static_cast` to the fixture's parameter type, so it does not have to be of that
215 exact type, only convertible to it.
216
217 **Caveat:** Consider the following example.
218
219 ```cpp
220 INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite,
221 ConvertGenerator(Values(std::string("s")), [](std::string_view s) { ... }));
222 ```
223
224 The `string` argument gets copied into the factory object returned by `Values`.
225 Then, because the generated type deduced from the lambda is `string_view`, the
226 factory object spawns a generator that holds a `string_view` referencing that
227 `string`. Unfortunately, by the time this generator gets invoked, the factory
228 object is gone and the `string_view` is dangling.
229
230 To overcome this problem you can specify the generated type explicitly:
231 `ConvertGenerator<std::string>(Values(std::string("s")), [](std::string_view s)
232 { ... })`. Alternatively, you can change the lambda's signature to take a
233 `std::string` or a `const std::string&` (the latter will not leave you with a
234 dangling reference because the type deduction strips off the reference and the
235 `const`).
236
237 ### TYPED_TEST_SUITE {#TYPED_TEST_SUITE}
238
239 `TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`)`
240 `TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`,`*`NameGenerator`*`)`
241
242 Defines a typed test suite based on the test fixture *`TestFixtureName`*. The
243 test suite name is *`TestFixtureName`*.
244
245 The argument *`TestFixtureName`* is a fixture class template, parameterized by a
246 type, for example:
247
248 ```cpp
249 template <typename T>
250 class MyFixture : public testing::Test {
251 public:
252 ...
253 using List = std::list<T>;
254 static T shared_;
255 T value_;
256 };
257 ```
258
259 The argument *`Types`* is a [`Types`](#Types) object representing the list of
260 types to run the tests on, for example:
261
262 ```cpp
263 using MyTypes = ::testing::Types<char, int, unsigned int>;
264 TYPED_TEST_SUITE(MyFixture, MyTypes);
265 ```
266
267 The type alias (`using` or `typedef`) is necessary for the `TYPED_TEST_SUITE`
268 macro to parse correctly.
269
270 The optional third argument *`NameGenerator`* allows specifying a class that
271 exposes a templated static function `GetName(int)`. For example:
272
273 ```cpp
274 class NameGenerator {
275 public:
276 template <typename T>
277 static std::string GetName(int) {
278 if constexpr (std::is_same_v<T, char>) return "char";
279 if constexpr (std::is_same_v<T, int>) return "int";
280 if constexpr (std::is_same_v<T, unsigned int>) return "unsignedInt";
281 }
282 };
283 TYPED_TEST_SUITE(MyFixture, MyTypes, NameGenerator);
284 ```
285
286 See also [`TYPED_TEST`](#TYPED_TEST) and
287 [Typed Tests](../advanced.md#typed-tests) for more information.
288
289 ### TYPED_TEST {#TYPED_TEST}
290
291 <pre>
292 TYPED_TEST(<em>TestSuiteName</em>, <em>TestName</em>) {
293 ... <em>statements</em> ...
294 }
295 </pre>
296
297 Defines an individual typed test named *`TestName`* in the typed test suite
298 *`TestSuiteName`*. The test suite must be defined with
299 [`TYPED_TEST_SUITE`](#TYPED_TEST_SUITE).
300
301 Within the test body, the special name `TypeParam` refers to the type parameter,
302 and `TestFixture` refers to the fixture class. See the following example:
303
304 ```cpp
305 TYPED_TEST(MyFixture, Example) {
306 // Inside a test, refer to the special name TypeParam to get the type
307 // parameter. Since we are inside a derived class template, C++ requires
308 // us to visit the members of MyFixture via 'this'.
309 TypeParam n = this->value_;
310
311 // To visit static members of the fixture, add the 'TestFixture::'
312 // prefix.
313 n += TestFixture::shared_;
314
315 // To refer to typedefs in the fixture, add the 'typename TestFixture::'
316 // prefix. The 'typename' is required to satisfy the compiler.
317 typename TestFixture::List values;
318
319 values.push_back(n);
320 ...
321 }
322 ```
323
324 For more information, see [Typed Tests](../advanced.md#typed-tests).
325
326 ### TYPED_TEST_SUITE_P {#TYPED_TEST_SUITE_P}
327
328 `TYPED_TEST_SUITE_P(`*`TestFixtureName`*`)`
329
330 Defines a type-parameterized test suite based on the test fixture
331 *`TestFixtureName`*. The test suite name is *`TestFixtureName`*.
332
333 The argument *`TestFixtureName`* is a fixture class template, parameterized by a
334 type. See [`TYPED_TEST_SUITE`](#TYPED_TEST_SUITE) for an example.
335
336 See also [`TYPED_TEST_P`](#TYPED_TEST_P) and
337 [Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more
338 information.
339
340 ### TYPED_TEST_P {#TYPED_TEST_P}
341
342 <pre>
343 TYPED_TEST_P(<em>TestSuiteName</em>, <em>TestName</em>) {
344 ... <em>statements</em> ...
345 }
346 </pre>
347
348 Defines an individual type-parameterized test named *`TestName`* in the
349 type-parameterized test suite *`TestSuiteName`*. The test suite must be defined
350 with [`TYPED_TEST_SUITE_P`](#TYPED_TEST_SUITE_P).
351
352 Within the test body, the special name `TypeParam` refers to the type parameter,
353 and `TestFixture` refers to the fixture class. See [`TYPED_TEST`](#TYPED_TEST)
354 for an example.
355
356 See also [`REGISTER_TYPED_TEST_SUITE_P`](#REGISTER_TYPED_TEST_SUITE_P) and
357 [Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more
358 information.
359
360 ### REGISTER_TYPED_TEST_SUITE_P {#REGISTER_TYPED_TEST_SUITE_P}
361
362 `REGISTER_TYPED_TEST_SUITE_P(`*`TestSuiteName`*`,`*`TestNames...`*`)`
363
364 Registers the type-parameterized tests *`TestNames...`* of the test suite
365 *`TestSuiteName`*. The test suite and tests must be defined with
366 [`TYPED_TEST_SUITE_P`](#TYPED_TEST_SUITE_P) and [`TYPED_TEST_P`](#TYPED_TEST_P).
367
368 For example:
369
370 ```cpp
371 // Define the test suite and tests.
372 TYPED_TEST_SUITE_P(MyFixture);
373 TYPED_TEST_P(MyFixture, HasPropertyA) { ... }
374 TYPED_TEST_P(MyFixture, HasPropertyB) { ... }
375
376 // Register the tests in the test suite.
377 REGISTER_TYPED_TEST_SUITE_P(MyFixture, HasPropertyA, HasPropertyB);
378 ```
379
380 See also [`INSTANTIATE_TYPED_TEST_SUITE_P`](#INSTANTIATE_TYPED_TEST_SUITE_P) and
381 [Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more
382 information.
383
384 ### INSTANTIATE_TYPED_TEST_SUITE_P {#INSTANTIATE_TYPED_TEST_SUITE_P}
385
386 `INSTANTIATE_TYPED_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`Types`*`)`
387
388 Instantiates the type-parameterized test suite *`TestSuiteName`*. The test suite
389 must be registered with
390 [`REGISTER_TYPED_TEST_SUITE_P`](#REGISTER_TYPED_TEST_SUITE_P).
391
392 The argument *`InstantiationName`* is a unique name for the instantiation of the
393 test suite, to distinguish between multiple instantiations. In test output, the
394 instantiation name is added as a prefix to the test suite name
395 *`TestSuiteName`*. If *`InstantiationName`* is empty
396 (`INSTANTIATE_TYPED_TEST_SUITE_P(, ...)`), no prefix is added.
397
398 The argument *`Types`* is a [`Types`](#Types) object representing the list of
399 types to run the tests on, for example:
400
401 ```cpp
402 using MyTypes = ::testing::Types<char, int, unsigned int>;
403 INSTANTIATE_TYPED_TEST_SUITE_P(MyInstantiation, MyFixture, MyTypes);
404 ```
405
406 The type alias (`using` or `typedef`) is necessary for the
407 `INSTANTIATE_TYPED_TEST_SUITE_P` macro to parse correctly.
408
409 For more information, see
410 [Type-Parameterized Tests](../advanced.md#type-parameterized-tests).
411
412 ### FRIEND_TEST {#FRIEND_TEST}
413
414 `FRIEND_TEST(`*`TestSuiteName`*`,`*`TestName`*`)`
415
416 Within a class body, declares an individual test as a friend of the class,
417 enabling the test to access private class members.
418
419 If the class is defined in a namespace, then in order to be friends of the
420 class, test fixtures and tests must be defined in the exact same namespace,
421 without inline or anonymous namespaces.
422
423 For example, if the class definition looks like the following:
424
425 ```cpp
426 namespace my_namespace {
427
428 class MyClass {
429 friend class MyClassTest;
430 FRIEND_TEST(MyClassTest, HasPropertyA);
431 FRIEND_TEST(MyClassTest, HasPropertyB);
432 ... definition of class MyClass ...
433 };
434
435 } // namespace my_namespace
436 ```
437
438 Then the test code should look like:
439
440 ```cpp
441 namespace my_namespace {
442
443 class MyClassTest : public testing::Test {
444 ...
445 };
446
447 TEST_F(MyClassTest, HasPropertyA) { ... }
448 TEST_F(MyClassTest, HasPropertyB) { ... }
449
450 } // namespace my_namespace
451 ```
452
453 See [Testing Private Code](../advanced.md#testing-private-code) for more
454 information.
455
456 ### SCOPED_TRACE {#SCOPED_TRACE}
457
458 `SCOPED_TRACE(`*`message`*`)`
459
460 Causes the current file name, line number, and the given message *`message`* to
461 be added to the failure message for each assertion failure that occurs in the
462 scope.
463
464 For more information, see
465 [Adding Traces to Assertions](../advanced.md#adding-traces-to-assertions).
466
467 See also the [`ScopedTrace` class](#ScopedTrace).
468
469 ### GTEST_SKIP {#GTEST_SKIP}
470
471 `GTEST_SKIP()`
472
473 Prevents further test execution at runtime.
474
475 Can be used in individual test cases or in the `SetUp()` methods of test
476 environments or test fixtures (classes derived from the
477 [`Environment`](#Environment) or [`Test`](#Test) classes). If used in a global
478 test environment `SetUp()` method, it skips all tests in the test program. If
479 used in a test fixture `SetUp()` method, it skips all tests in the corresponding
480 test suite.
481
482 Similar to assertions, `GTEST_SKIP` allows streaming a custom message into it.
483
484 See [Skipping Test Execution](../advanced.md#skipping-test-execution) for more
485 information.
486
487 ### GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST {#GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST}
488
489 `GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(`*`TestSuiteName`*`)`
490
491 Allows the value-parameterized test suite *`TestSuiteName`* to be
492 uninstantiated.
493
494 By default, every [`TEST_P`](#TEST_P) call without a corresponding
495 [`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P) call causes a failing
496 test in the test suite `GoogleTestVerification`.
497 `GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST` suppresses this failure for the
498 given test suite.
499
500 ## Classes and types
501
502 GoogleTest defines the following classes and types to help with writing tests.
503
504 ### AssertionResult {#AssertionResult}
505
506 `testing::AssertionResult`
507
508 A class for indicating whether an assertion was successful.
509
510 When the assertion wasn't successful, the `AssertionResult` object stores a
511 non-empty failure message that can be retrieved with the object's `message()`
512 method.
513
514 To create an instance of this class, use one of the factory functions
515 [`AssertionSuccess()`](#AssertionSuccess) or
516 [`AssertionFailure()`](#AssertionFailure).
517
518 ### AssertionException {#AssertionException}
519
520 `testing::AssertionException`
521
522 Exception which can be thrown from
523 [`TestEventListener::OnTestPartResult`](#TestEventListener::OnTestPartResult).
524
525 ### EmptyTestEventListener {#EmptyTestEventListener}
526
527 `testing::EmptyTestEventListener`
528
529 Provides an empty implementation of all methods in the
530 [`TestEventListener`](#TestEventListener) interface, such that a subclass only
531 needs to override the methods it cares about.
532
533 ### Environment {#Environment}
534
535 `testing::Environment`
536
537 Represents a global test environment. See
538 [Global Set-Up and Tear-Down](../advanced.md#global-set-up-and-tear-down).
539
540 #### Protected Methods {#Environment-protected}
541
542 ##### SetUp {#Environment::SetUp}
543
544 `virtual void Environment::SetUp()`
545
546 Override this to define how to set up the environment.
547
548 ##### TearDown {#Environment::TearDown}
549
550 `virtual void Environment::TearDown()`
551
552 Override this to define how to tear down the environment.
553
554 ### ScopedTrace {#ScopedTrace}
555
556 `testing::ScopedTrace`
557
558 An instance of this class causes a trace to be included in every test failure
559 message generated by code in the scope of the lifetime of the `ScopedTrace`
560 instance. The effect is undone with the destruction of the instance.
561
562 The `ScopedTrace` constructor has the following form:
563
564 ```cpp
565 template <typename T>
566 ScopedTrace(const char* file, int line, const T& message)
567 ```
568
569 Example usage:
570
571 ```cpp
572 testing::ScopedTrace trace("file.cc", 123, "message");
573 ```
574
575 The resulting trace includes the given source file path and line number, and the
576 given message. The `message` argument can be anything streamable to
577 `std::ostream`.
578
579 See also [`SCOPED_TRACE`](#SCOPED_TRACE).
580
581 ### Test {#Test}
582
583 `testing::Test`
584
585 The abstract class that all tests inherit from. `Test` is not copyable.
586
587 #### Public Methods {#Test-public}
588
589 ##### SetUpTestSuite {#Test::SetUpTestSuite}
590
591 `static void Test::SetUpTestSuite()`
592
593 Performs shared setup for all tests in the test suite. GoogleTest calls
594 `SetUpTestSuite()` before running the first test in the test suite.
595
596 ##### TearDownTestSuite {#Test::TearDownTestSuite}
597
598 `static void Test::TearDownTestSuite()`
599
600 Performs shared teardown for all tests in the test suite. GoogleTest calls
601 `TearDownTestSuite()` after running the last test in the test suite.
602
603 ##### HasFatalFailure {#Test::HasFatalFailure}
604
605 `static bool Test::HasFatalFailure()`
606
607 Returns true if and only if the current test has a fatal failure.
608
609 ##### HasNonfatalFailure {#Test::HasNonfatalFailure}
610
611 `static bool Test::HasNonfatalFailure()`
612
613 Returns true if and only if the current test has a nonfatal failure.
614
615 ##### HasFailure {#Test::HasFailure}
616
617 `static bool Test::HasFailure()`
618
619 Returns true if and only if the current test has any failure, either fatal or
620 nonfatal.
621
622 ##### IsSkipped {#Test::IsSkipped}
623
624 `static bool Test::IsSkipped()`
625
626 Returns true if and only if the current test was skipped.
627
628 ##### RecordProperty {#Test::RecordProperty}
629
630 `static void Test::RecordProperty(const std::string& key, const std::string&
631 value)` \
632 `static void Test::RecordProperty(const std::string& key, int value)`
633
634 Logs a property for the current test, test suite, or entire invocation of the
635 test program. Only the last value for a given key is logged.
636
637 The key must be a valid XML attribute name, and cannot conflict with the ones
638 already used by GoogleTest (`name`, `file`, `line`, `status`, `time`,
639 `classname`, `type_param`, and `value_param`).
640
641 `RecordProperty` is `public static` so it can be called from utility functions
642 that are not members of the test fixture.
643
644 Calls to `RecordProperty` made during the lifespan of the test (from the moment
645 its constructor starts to the moment its destructor finishes) are output in XML
646 as attributes of the `<testcase>` element. Properties recorded from a fixture's
647 `SetUpTestSuite` or `TearDownTestSuite` methods are logged as attributes of the
648 corresponding `<testsuite>` element. Calls to `RecordProperty` made in the
649 global context (before or after invocation of `RUN_ALL_TESTS` or from the
650 `SetUp`/`TearDown` methods of registered `Environment` objects) are output as
651 attributes of the `<testsuites>` element.
652
653 #### Protected Methods {#Test-protected}
654
655 ##### SetUp {#Test::SetUp}
656
657 `virtual void Test::SetUp()`
658
659 Override this to perform test fixture setup. GoogleTest calls `SetUp()` before
660 running each individual test.
661
662 ##### TearDown {#Test::TearDown}
663
664 `virtual void Test::TearDown()`
665
666 Override this to perform test fixture teardown. GoogleTest calls `TearDown()`
667 after running each individual test.
668
669 ### TestWithParam {#TestWithParam}
670
671 `testing::TestWithParam<T>`
672
673 A convenience class which inherits from both [`Test`](#Test) and
674 [`WithParamInterface<T>`](#WithParamInterface).
675
676 ### TestSuite {#TestSuite}
677
678 Represents a test suite. `TestSuite` is not copyable.
679
680 #### Public Methods {#TestSuite-public}
681
682 ##### name {#TestSuite::name}
683
684 `const char* TestSuite::name() const`
685
686 Gets the name of the test suite.
687
688 ##### type_param {#TestSuite::type_param}
689
690 `const char* TestSuite::type_param() const`
691
692 Returns the name of the parameter type, or `NULL` if this is not a typed or
693 type-parameterized test suite. See [Typed Tests](../advanced.md#typed-tests) and
694 [Type-Parameterized Tests](../advanced.md#type-parameterized-tests).
695
696 ##### should_run {#TestSuite::should_run}
697
698 `bool TestSuite::should_run() const`
699
700 Returns true if any test in this test suite should run.
701
702 ##### successful_test_count {#TestSuite::successful_test_count}
703
704 `int TestSuite::successful_test_count() const`
705
706 Gets the number of successful tests in this test suite.
707
708 ##### skipped_test_count {#TestSuite::skipped_test_count}
709
710 `int TestSuite::skipped_test_count() const`
711
712 Gets the number of skipped tests in this test suite.
713
714 ##### failed_test_count {#TestSuite::failed_test_count}
715
716 `int TestSuite::failed_test_count() const`
717
718 Gets the number of failed tests in this test suite.
719
720 ##### reportable_disabled_test_count {#TestSuite::reportable_disabled_test_count}
721
722 `int TestSuite::reportable_disabled_test_count() const`
723
724 Gets the number of disabled tests that will be reported in the XML report.
725
726 ##### disabled_test_count {#TestSuite::disabled_test_count}
727
728 `int TestSuite::disabled_test_count() const`
729
730 Gets the number of disabled tests in this test suite.
731
732 ##### reportable_test_count {#TestSuite::reportable_test_count}
733
734 `int TestSuite::reportable_test_count() const`
735
736 Gets the number of tests to be printed in the XML report.
737
738 ##### test_to_run_count {#TestSuite::test_to_run_count}
739
740 `int TestSuite::test_to_run_count() const`
741
742 Get the number of tests in this test suite that should run.
743
744 ##### total_test_count {#TestSuite::total_test_count}
745
746 `int TestSuite::total_test_count() const`
747
748 Gets the number of all tests in this test suite.
749
750 ##### Passed {#TestSuite::Passed}
751
752 `bool TestSuite::Passed() const`
753
754 Returns true if and only if the test suite passed.
755
756 ##### Failed {#TestSuite::Failed}
757
758 `bool TestSuite::Failed() const`
759
760 Returns true if and only if the test suite failed.
761
762 ##### elapsed_time {#TestSuite::elapsed_time}
763
764 `TimeInMillis TestSuite::elapsed_time() const`
765
766 Returns the elapsed time, in milliseconds.
767
768 ##### start_timestamp {#TestSuite::start_timestamp}
769
770 `TimeInMillis TestSuite::start_timestamp() const`
771
772 Gets the time of the test suite start, in ms from the start of the UNIX epoch.
773
774 ##### GetTestInfo {#TestSuite::GetTestInfo}
775
776 `const TestInfo* TestSuite::GetTestInfo(int i) const`
777
778 Returns the [`TestInfo`](#TestInfo) for the `i`-th test among all the tests. `i`
779 can range from 0 to `total_test_count() - 1`. If `i` is not in that range,
780 returns `NULL`.
781
782 ##### ad_hoc_test_result {#TestSuite::ad_hoc_test_result}
783
784 `const TestResult& TestSuite::ad_hoc_test_result() const`
785
786 Returns the [`TestResult`](#TestResult) that holds test properties recorded
787 during execution of `SetUpTestSuite` and `TearDownTestSuite`.
788
789 ### TestInfo {#TestInfo}
790
791 `testing::TestInfo`
792
793 Stores information about a test.
794
795 #### Public Methods {#TestInfo-public}
796
797 ##### test_suite_name {#TestInfo::test_suite_name}
798
799 `const char* TestInfo::test_suite_name() const`
800
801 Returns the test suite name.
802
803 ##### name {#TestInfo::name}
804
805 `const char* TestInfo::name() const`
806
807 Returns the test name.
808
809 ##### type_param {#TestInfo::type_param}
810
811 `const char* TestInfo::type_param() const`
812
813 Returns the name of the parameter type, or `NULL` if this is not a typed or
814 type-parameterized test. See [Typed Tests](../advanced.md#typed-tests) and
815 [Type-Parameterized Tests](../advanced.md#type-parameterized-tests).
816
817 ##### value_param {#TestInfo::value_param}
818
819 `const char* TestInfo::value_param() const`
820
821 Returns the text representation of the value parameter, or `NULL` if this is not
822 a value-parameterized test. See
823 [Value-Parameterized Tests](../advanced.md#value-parameterized-tests).
824
825 ##### file {#TestInfo::file}
826
827 `const char* TestInfo::file() const`
828
829 Returns the file name where this test is defined.
830
831 ##### line {#TestInfo::line}
832
833 `int TestInfo::line() const`
834
835 Returns the line where this test is defined.
836
837 ##### is_in_another_shard {#TestInfo::is_in_another_shard}
838
839 `bool TestInfo::is_in_another_shard() const`
840
841 Returns true if this test should not be run because it's in another shard.
842
843 ##### should_run {#TestInfo::should_run}
844
845 `bool TestInfo::should_run() const`
846
847 Returns true if this test should run, that is if the test is not disabled (or it
848 is disabled but the `also_run_disabled_tests` flag has been specified) and its
849 full name matches the user-specified filter.
850
851 GoogleTest allows the user to filter the tests by their full names. Only the
852 tests that match the filter will run. See
853 [Running a Subset of the Tests](../advanced.md#running-a-subset-of-the-tests)
854 for more information.
855
856 ##### is_reportable {#TestInfo::is_reportable}
857
858 `bool TestInfo::is_reportable() const`
859
860 Returns true if and only if this test will appear in the XML report.
861
862 ##### result {#TestInfo::result}
863
864 `const TestResult* TestInfo::result() const`
865
866 Returns the result of the test. See [`TestResult`](#TestResult).
867
868 ### TestParamInfo {#TestParamInfo}
869
870 `testing::TestParamInfo<T>`
871
872 Describes a parameter to a value-parameterized test. The type `T` is the type of
873 the parameter.
874
875 Contains the fields `param` and `index` which hold the value of the parameter
876 and its integer index respectively.
877
878 ### UnitTest {#UnitTest}
879
880 `testing::UnitTest`
881
882 This class contains information about the test program.
883
884 `UnitTest` is a singleton class. The only instance is created when
885 `UnitTest::GetInstance()` is first called. This instance is never deleted.
886
887 `UnitTest` is not copyable.
888
889 #### Public Methods {#UnitTest-public}
890
891 ##### GetInstance {#UnitTest::GetInstance}
892
893 `static UnitTest* UnitTest::GetInstance()`
894
895 Gets the singleton `UnitTest` object. The first time this method is called, a
896 `UnitTest` object is constructed and returned. Consecutive calls will return the
897 same object.
898
899 ##### original_working_dir {#UnitTest::original_working_dir}
900
901 `const char* UnitTest::original_working_dir() const`
902
903 Returns the working directory when the first [`TEST()`](#TEST) or
904 [`TEST_F()`](#TEST_F) was executed. The `UnitTest` object owns the string.
905
906 ##### current_test_suite {#UnitTest::current_test_suite}
907
908 `const TestSuite* UnitTest::current_test_suite() const`
909
910 Returns the [`TestSuite`](#TestSuite) object for the test that's currently
911 running, or `NULL` if no test is running.
912
913 ##### current_test_info {#UnitTest::current_test_info}
914
915 `const TestInfo* UnitTest::current_test_info() const`
916
917 Returns the [`TestInfo`](#TestInfo) object for the test that's currently
918 running, or `NULL` if no test is running.
919
920 ##### random_seed {#UnitTest::random_seed}
921
922 `int UnitTest::random_seed() const`
923
924 Returns the random seed used at the start of the current test run.
925
926 ##### successful_test_suite_count {#UnitTest::successful_test_suite_count}
927
928 `int UnitTest::successful_test_suite_count() const`
929
930 Gets the number of successful test suites.
931
932 ##### failed_test_suite_count {#UnitTest::failed_test_suite_count}
933
934 `int UnitTest::failed_test_suite_count() const`
935
936 Gets the number of failed test suites.
937
938 ##### total_test_suite_count {#UnitTest::total_test_suite_count}
939
940 `int UnitTest::total_test_suite_count() const`
941
942 Gets the number of all test suites.
943
944 ##### test_suite_to_run_count {#UnitTest::test_suite_to_run_count}
945
946 `int UnitTest::test_suite_to_run_count() const`
947
948 Gets the number of all test suites that contain at least one test that should
949 run.
950
951 ##### successful_test_count {#UnitTest::successful_test_count}
952
953 `int UnitTest::successful_test_count() const`
954
955 Gets the number of successful tests.
956
957 ##### skipped_test_count {#UnitTest::skipped_test_count}
958
959 `int UnitTest::skipped_test_count() const`
960
961 Gets the number of skipped tests.
962
963 ##### failed_test_count {#UnitTest::failed_test_count}
964
965 `int UnitTest::failed_test_count() const`
966
967 Gets the number of failed tests.
968
969 ##### reportable_disabled_test_count {#UnitTest::reportable_disabled_test_count}
970
971 `int UnitTest::reportable_disabled_test_count() const`
972
973 Gets the number of disabled tests that will be reported in the XML report.
974
975 ##### disabled_test_count {#UnitTest::disabled_test_count}
976
977 `int UnitTest::disabled_test_count() const`
978
979 Gets the number of disabled tests.
980
981 ##### reportable_test_count {#UnitTest::reportable_test_count}
982
983 `int UnitTest::reportable_test_count() const`
984
985 Gets the number of tests to be printed in the XML report.
986
987 ##### total_test_count {#UnitTest::total_test_count}
988
989 `int UnitTest::total_test_count() const`
990
991 Gets the number of all tests.
992
993 ##### test_to_run_count {#UnitTest::test_to_run_count}
994
995 `int UnitTest::test_to_run_count() const`
996
997 Gets the number of tests that should run.
998
999 ##### start_timestamp {#UnitTest::start_timestamp}
1000
1001 `TimeInMillis UnitTest::start_timestamp() const`
1002
1003 Gets the time of the test program start, in ms from the start of the UNIX epoch.
1004
1005 ##### elapsed_time {#UnitTest::elapsed_time}
1006
1007 `TimeInMillis UnitTest::elapsed_time() const`
1008
1009 Gets the elapsed time, in milliseconds.
1010
1011 ##### Passed {#UnitTest::Passed}
1012
1013 `bool UnitTest::Passed() const`
1014
1015 Returns true if and only if the unit test passed (i.e. all test suites passed).
1016
1017 ##### Failed {#UnitTest::Failed}
1018
1019 `bool UnitTest::Failed() const`
1020
1021 Returns true if and only if the unit test failed (i.e. some test suite failed or
1022 something outside of all tests failed).
1023
1024 ##### GetTestSuite {#UnitTest::GetTestSuite}
1025
1026 `const TestSuite* UnitTest::GetTestSuite(int i) const`
1027
1028 Gets the [`TestSuite`](#TestSuite) object for the `i`-th test suite among all
1029 the test suites. `i` can range from 0 to `total_test_suite_count() - 1`. If `i`
1030 is not in that range, returns `NULL`.
1031
1032 ##### ad_hoc_test_result {#UnitTest::ad_hoc_test_result}
1033
1034 `const TestResult& UnitTest::ad_hoc_test_result() const`
1035
1036 Returns the [`TestResult`](#TestResult) containing information on test failures
1037 and properties logged outside of individual test suites.
1038
1039 ##### listeners {#UnitTest::listeners}
1040
1041 `TestEventListeners& UnitTest::listeners()`
1042
1043 Returns the list of event listeners that can be used to track events inside
1044 GoogleTest. See [`TestEventListeners`](#TestEventListeners).
1045
1046 ### TestEventListener {#TestEventListener}
1047
1048 `testing::TestEventListener`
1049
1050 The interface for tracing execution of tests. The methods below are listed in
1051 the order the corresponding events are fired.
1052
1053 #### Public Methods {#TestEventListener-public}
1054
1055 ##### OnTestProgramStart {#TestEventListener::OnTestProgramStart}
1056
1057 `virtual void TestEventListener::OnTestProgramStart(const UnitTest& unit_test)`
1058
1059 Fired before any test activity starts.
1060
1061 ##### OnTestIterationStart {#TestEventListener::OnTestIterationStart}
1062
1063 `virtual void TestEventListener::OnTestIterationStart(const UnitTest& unit_test,
1064 int iteration)`
1065
1066 Fired before each iteration of tests starts. There may be more than one
1067 iteration if `GTEST_FLAG(repeat)` is set. `iteration` is the iteration index,
1068 starting from 0.
1069
1070 ##### OnEnvironmentsSetUpStart {#TestEventListener::OnEnvironmentsSetUpStart}
1071
1072 `virtual void TestEventListener::OnEnvironmentsSetUpStart(const UnitTest&
1073 unit_test)`
1074
1075 Fired before environment set-up for each iteration of tests starts.
1076
1077 ##### OnEnvironmentsSetUpEnd {#TestEventListener::OnEnvironmentsSetUpEnd}
1078
1079 `virtual void TestEventListener::OnEnvironmentsSetUpEnd(const UnitTest&
1080 unit_test)`
1081
1082 Fired after environment set-up for each iteration of tests ends.
1083
1084 ##### OnTestSuiteStart {#TestEventListener::OnTestSuiteStart}
1085
1086 `virtual void TestEventListener::OnTestSuiteStart(const TestSuite& test_suite)`
1087
1088 Fired before the test suite starts.
1089
1090 ##### OnTestStart {#TestEventListener::OnTestStart}
1091
1092 `virtual void TestEventListener::OnTestStart(const TestInfo& test_info)`
1093
1094 Fired before the test starts.
1095
1096 ##### OnTestPartResult {#TestEventListener::OnTestPartResult}
1097
1098 `virtual void TestEventListener::OnTestPartResult(const TestPartResult&
1099 test_part_result)`
1100
1101 Fired after a failed assertion or a `SUCCEED()` invocation. If you want to throw
1102 an exception from this function to skip to the next test, it must be an
1103 [`AssertionException`](#AssertionException) or inherited from it.
1104
1105 ##### OnTestEnd {#TestEventListener::OnTestEnd}
1106
1107 `virtual void TestEventListener::OnTestEnd(const TestInfo& test_info)`
1108
1109 Fired after the test ends.
1110
1111 ##### OnTestSuiteEnd {#TestEventListener::OnTestSuiteEnd}
1112
1113 `virtual void TestEventListener::OnTestSuiteEnd(const TestSuite& test_suite)`
1114
1115 Fired after the test suite ends.
1116
1117 ##### OnEnvironmentsTearDownStart {#TestEventListener::OnEnvironmentsTearDownStart}
1118
1119 `virtual void TestEventListener::OnEnvironmentsTearDownStart(const UnitTest&
1120 unit_test)`
1121
1122 Fired before environment tear-down for each iteration of tests starts.
1123
1124 ##### OnEnvironmentsTearDownEnd {#TestEventListener::OnEnvironmentsTearDownEnd}
1125
1126 `virtual void TestEventListener::OnEnvironmentsTearDownEnd(const UnitTest&
1127 unit_test)`
1128
1129 Fired after environment tear-down for each iteration of tests ends.
1130
1131 ##### OnTestIterationEnd {#TestEventListener::OnTestIterationEnd}
1132
1133 `virtual void TestEventListener::OnTestIterationEnd(const UnitTest& unit_test,
1134 int iteration)`
1135
1136 Fired after each iteration of tests finishes.
1137
1138 ##### OnTestProgramEnd {#TestEventListener::OnTestProgramEnd}
1139
1140 `virtual void TestEventListener::OnTestProgramEnd(const UnitTest& unit_test)`
1141
1142 Fired after all test activities have ended.
1143
1144 ### TestEventListeners {#TestEventListeners}
1145
1146 `testing::TestEventListeners`
1147
1148 Lets users add listeners to track events in GoogleTest.
1149
1150 #### Public Methods {#TestEventListeners-public}
1151
1152 ##### Append {#TestEventListeners::Append}
1153
1154 `void TestEventListeners::Append(TestEventListener* listener)`
1155
1156 Appends an event listener to the end of the list. GoogleTest assumes ownership
1157 of the listener (i.e. it will delete the listener when the test program
1158 finishes).
1159
1160 ##### Release {#TestEventListeners::Release}
1161
1162 `TestEventListener* TestEventListeners::Release(TestEventListener* listener)`
1163
1164 Removes the given event listener from the list and returns it. It then becomes
1165 the caller's responsibility to delete the listener. Returns `NULL` if the
1166 listener is not found in the list.
1167
1168 ##### default_result_printer {#TestEventListeners::default_result_printer}
1169
1170 `TestEventListener* TestEventListeners::default_result_printer() const`
1171
1172 Returns the standard listener responsible for the default console output. Can be
1173 removed from the listeners list to shut down default console output. Note that
1174 removing this object from the listener list with
1175 [`Release()`](#TestEventListeners::Release) transfers its ownership to the
1176 caller and makes this function return `NULL` the next time.
1177
1178 ##### default_xml_generator {#TestEventListeners::default_xml_generator}
1179
1180 `TestEventListener* TestEventListeners::default_xml_generator() const`
1181
1182 Returns the standard listener responsible for the default XML output controlled
1183 by the `--gtest_output=xml` flag. Can be removed from the listeners list by
1184 users who want to shut down the default XML output controlled by this flag and
1185 substitute it with custom one. Note that removing this object from the listener
1186 list with [`Release()`](#TestEventListeners::Release) transfers its ownership to
1187 the caller and makes this function return `NULL` the next time.
1188
1189 ### TestPartResult {#TestPartResult}
1190
1191 `testing::TestPartResult`
1192
1193 A copyable object representing the result of a test part (i.e. an assertion or
1194 an explicit `FAIL()`, `ADD_FAILURE()`, or `SUCCESS()`).
1195
1196 #### Public Methods {#TestPartResult-public}
1197
1198 ##### type {#TestPartResult::type}
1199
1200 `Type TestPartResult::type() const`
1201
1202 Gets the outcome of the test part.
1203
1204 The return type `Type` is an enum defined as follows:
1205
1206 ```cpp
1207 enum Type {
1208 kSuccess, // Succeeded.
1209 kNonFatalFailure, // Failed but the test can continue.
1210 kFatalFailure, // Failed and the test should be terminated.
1211 kSkip // Skipped.
1212 };
1213 ```
1214
1215 ##### file_name {#TestPartResult::file_name}
1216
1217 `const char* TestPartResult::file_name() const`
1218
1219 Gets the name of the source file where the test part took place, or `NULL` if
1220 it's unknown.
1221
1222 ##### line_number {#TestPartResult::line_number}
1223
1224 `int TestPartResult::line_number() const`
1225
1226 Gets the line in the source file where the test part took place, or `-1` if it's
1227 unknown.
1228
1229 ##### summary {#TestPartResult::summary}
1230
1231 `const char* TestPartResult::summary() const`
1232
1233 Gets the summary of the failure message.
1234
1235 ##### message {#TestPartResult::message}
1236
1237 `const char* TestPartResult::message() const`
1238
1239 Gets the message associated with the test part.
1240
1241 ##### skipped {#TestPartResult::skipped}
1242
1243 `bool TestPartResult::skipped() const`
1244
1245 Returns true if and only if the test part was skipped.
1246
1247 ##### passed {#TestPartResult::passed}
1248
1249 `bool TestPartResult::passed() const`
1250
1251 Returns true if and only if the test part passed.
1252
1253 ##### nonfatally_failed {#TestPartResult::nonfatally_failed}
1254
1255 `bool TestPartResult::nonfatally_failed() const`
1256
1257 Returns true if and only if the test part non-fatally failed.
1258
1259 ##### fatally_failed {#TestPartResult::fatally_failed}
1260
1261 `bool TestPartResult::fatally_failed() const`
1262
1263 Returns true if and only if the test part fatally failed.
1264
1265 ##### failed {#TestPartResult::failed}
1266
1267 `bool TestPartResult::failed() const`
1268
1269 Returns true if and only if the test part failed.
1270
1271 ### TestProperty {#TestProperty}
1272
1273 `testing::TestProperty`
1274
1275 A copyable object representing a user-specified test property which can be
1276 output as a key/value string pair.
1277
1278 #### Public Methods {#TestProperty-public}
1279
1280 ##### key {#key}
1281
1282 `const char* key() const`
1283
1284 Gets the user-supplied key.
1285
1286 ##### value {#value}
1287
1288 `const char* value() const`
1289
1290 Gets the user-supplied value.
1291
1292 ##### SetValue {#SetValue}
1293
1294 `void SetValue(const std::string& new_value)`
1295
1296 Sets a new value, overriding the previous one.
1297
1298 ### TestResult {#TestResult}
1299
1300 `testing::TestResult`
1301
1302 Contains information about the result of a single test.
1303
1304 `TestResult` is not copyable.
1305
1306 #### Public Methods {#TestResult-public}
1307
1308 ##### total_part_count {#TestResult::total_part_count}
1309
1310 `int TestResult::total_part_count() const`
1311
1312 Gets the number of all test parts. This is the sum of the number of successful
1313 test parts and the number of failed test parts.
1314
1315 ##### test_property_count {#TestResult::test_property_count}
1316
1317 `int TestResult::test_property_count() const`
1318
1319 Returns the number of test properties.
1320
1321 ##### Passed {#TestResult::Passed}
1322
1323 `bool TestResult::Passed() const`
1324
1325 Returns true if and only if the test passed (i.e. no test part failed).
1326
1327 ##### Skipped {#TestResult::Skipped}
1328
1329 `bool TestResult::Skipped() const`
1330
1331 Returns true if and only if the test was skipped.
1332
1333 ##### Failed {#TestResult::Failed}
1334
1335 `bool TestResult::Failed() const`
1336
1337 Returns true if and only if the test failed.
1338
1339 ##### HasFatalFailure {#TestResult::HasFatalFailure}
1340
1341 `bool TestResult::HasFatalFailure() const`
1342
1343 Returns true if and only if the test fatally failed.
1344
1345 ##### HasNonfatalFailure {#TestResult::HasNonfatalFailure}
1346
1347 `bool TestResult::HasNonfatalFailure() const`
1348
1349 Returns true if and only if the test has a non-fatal failure.
1350
1351 ##### elapsed_time {#TestResult::elapsed_time}
1352
1353 `TimeInMillis TestResult::elapsed_time() const`
1354
1355 Returns the elapsed time, in milliseconds.
1356
1357 ##### start_timestamp {#TestResult::start_timestamp}
1358
1359 `TimeInMillis TestResult::start_timestamp() const`
1360
1361 Gets the time of the test case start, in ms from the start of the UNIX epoch.
1362
1363 ##### GetTestPartResult {#TestResult::GetTestPartResult}
1364
1365 `const TestPartResult& TestResult::GetTestPartResult(int i) const`
1366
1367 Returns the [`TestPartResult`](#TestPartResult) for the `i`-th test part result
1368 among all the results. `i` can range from 0 to `total_part_count() - 1`. If `i`
1369 is not in that range, aborts the program.
1370
1371 ##### GetTestProperty {#TestResult::GetTestProperty}
1372
1373 `const TestProperty& TestResult::GetTestProperty(int i) const`
1374
1375 Returns the [`TestProperty`](#TestProperty) object for the `i`-th test property.
1376 `i` can range from 0 to `test_property_count() - 1`. If `i` is not in that
1377 range, aborts the program.
1378
1379 ### TimeInMillis {#TimeInMillis}
1380
1381 `testing::TimeInMillis`
1382
1383 An integer type representing time in milliseconds.
1384
1385 ### Types {#Types}
1386
1387 `testing::Types<T...>`
1388
1389 Represents a list of types for use in typed tests and type-parameterized tests.
1390
1391 The template argument `T...` can be any number of types, for example:
1392
1393 ```
1394 testing::Types<char, int, unsigned int>
1395 ```
1396
1397 See [Typed Tests](../advanced.md#typed-tests) and
1398 [Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more
1399 information.
1400
1401 ### WithParamInterface {#WithParamInterface}
1402
1403 `testing::WithParamInterface<T>`
1404
1405 The pure interface class that all value-parameterized tests inherit from.
1406
1407 A value-parameterized test fixture class must inherit from both [`Test`](#Test)
1408 and `WithParamInterface`. In most cases that just means inheriting from
1409 [`TestWithParam`](#TestWithParam), but more complicated test hierarchies may
1410 need to inherit from `Test` and `WithParamInterface` at different levels.
1411
1412 This interface defines the type alias `ParamType` for the parameter type `T` and
1413 has support for accessing the test parameter value via the `GetParam()` method:
1414
1415 ```
1416 static const ParamType& GetParam()
1417 ```
1418
1419 For more information, see
1420 [Value-Parameterized Tests](../advanced.md#value-parameterized-tests).
1421
1422 ## Functions
1423
1424 GoogleTest defines the following functions to help with writing and running
1425 tests.
1426
1427 ### InitGoogleTest {#InitGoogleTest}
1428
1429 `void testing::InitGoogleTest(int* argc, char** argv)` \
1430 `void testing::InitGoogleTest(int* argc, wchar_t** argv)` \
1431 `void testing::InitGoogleTest()`
1432
1433 Initializes GoogleTest. This must be called before calling
1434 [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS). In particular, it parses the command line
1435 for the flags that GoogleTest recognizes. Whenever a GoogleTest flag is seen, it
1436 is removed from `argv`, and `*argc` is decremented. Keep in mind that `argv`
1437 must terminate with a `NULL` pointer (i.e. `argv[argc]` is `NULL`), which is
1438 already the case with the default `argv` passed to `main`.
1439
1440 No value is returned. Instead, the GoogleTest flag variables are updated.
1441
1442 The `InitGoogleTest(int* argc, wchar_t** argv)` overload can be used in Windows
1443 programs compiled in `UNICODE` mode.
1444
1445 The argument-less `InitGoogleTest()` overload can be used on Arduino/embedded
1446 platforms where there is no `argc`/`argv`.
1447
1448 ### AddGlobalTestEnvironment {#AddGlobalTestEnvironment}
1449
1450 `Environment* testing::AddGlobalTestEnvironment(Environment* env)`
1451
1452 Adds a test environment to the test program. Must be called before
1453 [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS) is called. See
1454 [Global Set-Up and Tear-Down](../advanced.md#global-set-up-and-tear-down) for
1455 more information.
1456
1457 See also [`Environment`](#Environment).
1458
1459 ### RegisterTest {#RegisterTest}
1460
1461 ```cpp
1462 template <typename Factory>
1463 TestInfo* testing::RegisterTest(const char* test_suite_name, const char* test_name,
1464 const char* type_param, const char* value_param,
1465 const char* file, int line, Factory factory)
1466 ```
1467
1468 Dynamically registers a test with the framework.
1469
1470 The `factory` argument is a factory callable (move-constructible) object or
1471 function pointer that creates a new instance of the `Test` object. It handles
1472 ownership to the caller. The signature of the callable is `Fixture*()`, where
1473 `Fixture` is the test fixture class for the test. All tests registered with the
1474 same `test_suite_name` must return the same fixture type. This is checked at
1475 runtime.
1476
1477 The framework will infer the fixture class from the factory and will call the
1478 `SetUpTestSuite` and `TearDownTestSuite` methods for it.
1479
1480 Must be called before [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS) is invoked, otherwise
1481 behavior is undefined.
1482
1483 See
1484 [Registering tests programmatically](../advanced.md#registering-tests-programmatically)
1485 for more information.
1486
1487 ### RUN_ALL_TESTS {#RUN_ALL_TESTS}
1488
1489 `int RUN_ALL_TESTS()`
1490
1491 Use this function in `main()` to run all tests. It returns `0` if all tests are
1492 successful, or `1` otherwise.
1493
1494 `RUN_ALL_TESTS()` should be invoked after the command line has been parsed by
1495 [`InitGoogleTest()`](#InitGoogleTest).
1496
1497 This function was formerly a macro; thus, it is in the global namespace and has
1498 an all-caps name.
1499
1500 ### AssertionSuccess {#AssertionSuccess}
1501
1502 `AssertionResult testing::AssertionSuccess()`
1503
1504 Creates a successful assertion result. See
1505 [`AssertionResult`](#AssertionResult).
1506
1507 ### AssertionFailure {#AssertionFailure}
1508
1509 `AssertionResult testing::AssertionFailure()`
1510
1511 Creates a failed assertion result. Use the `<<` operator to store a failure
1512 message:
1513
1514 ```cpp
1515 testing::AssertionFailure() << "My failure message";
1516 ```
1517
1518 See [`AssertionResult`](#AssertionResult).
1519
1520 ### StaticAssertTypeEq {#StaticAssertTypeEq}
1521
1522 `testing::StaticAssertTypeEq<T1, T2>()`
1523
1524 Compile-time assertion for type equality. Compiles if and only if `T1` and `T2`
1525 are the same type. The value it returns is irrelevant.
1526
1527 See [Type Assertions](../advanced.md#type-assertions) for more information.
1528
1529 ### PrintToString {#PrintToString}
1530
1531 `std::string testing::PrintToString(x)`
1532
1533 Prints any value `x` using GoogleTest's value printer.
1534
1535 See
1536 [Teaching GoogleTest How to Print Your Values](../advanced.md#teaching-googletest-how-to-print-your-values)
1537 for more information.
1538
1539 ### PrintToStringParamName {#PrintToStringParamName}
1540
1541 `std::string testing::PrintToStringParamName(TestParamInfo<T>& info)`
1542
1543 A built-in parameterized test name generator which returns the result of
1544 [`PrintToString`](#PrintToString) called on `info.param`. Does not work when the
1545 test parameter is a `std::string` or C string. See
1546 [Specifying Names for Value-Parameterized Test Parameters](../advanced.md#specifying-names-for-value-parameterized-test-parameters)
1547 for more information.
1548
1549 See also [`TestParamInfo`](#TestParamInfo) and
1550 [`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P).