1- # Googletest FAQ
1+ # GoogleTest FAQ
22
33## Why should test suite names and test names not contain underscore?
44
55{: .callout .note}
6- Note: Googletest reserves underscore (` _ ` ) for special purpose keywords, such as
6+ Note: GoogleTest reserves underscore (` _ ` ) for special purpose keywords, such as
77[ the ` DISABLED_ ` prefix] ( advanced.md#temporarily-disabling-tests ) , in addition
88to the following rationale.
99
@@ -50,15 +50,15 @@ Now, the two `TEST`s will both generate the same class
5050
5151So for simplicity, we just ask the users to avoid `_` in `TestSuiteName` and
5252`TestName`. The rule is more constraining than necessary, but it's simple and
53- easy to remember. It also gives googletest some wiggle room in case its
53+ easy to remember. It also gives GoogleTest some wiggle room in case its
5454implementation needs to change in the future.
5555
5656If you violate the rule, there may not be immediate consequences, but your test
5757may (just may) break with a new compiler (or a new version of the compiler you
58- are using) or with a new version of googletest . Therefore it's best to follow
58+ are using) or with a new version of GoogleTest . Therefore it's best to follow
5959the rule.
6060
61- ## Why does googletest support `EXPECT_EQ(NULL, ptr)` and `ASSERT_EQ(NULL, ptr)` but not `EXPECT_NE(NULL, ptr)` and `ASSERT_NE(NULL, ptr)`?
61+ ## Why does GoogleTest support `EXPECT_EQ(NULL, ptr)` and `ASSERT_EQ(NULL, ptr)` but not `EXPECT_NE(NULL, ptr)` and `ASSERT_NE(NULL, ptr)`?
6262
6363First of all, you can use `nullptr` with each of these macros, e.g.
6464`EXPECT_EQ(ptr, nullptr)`, `EXPECT_NE(ptr, nullptr)`, `ASSERT_EQ(ptr, nullptr)`,
@@ -68,7 +68,7 @@ because `nullptr` does not have the type problems that `NULL` does.
6868Due to some peculiarity of C++, it requires some non-trivial template meta
6969programming tricks to support using `NULL` as an argument of the `EXPECT_XX()`
7070and `ASSERT_XX()` macros. Therefore we only do it where it's most needed
71- (otherwise we make the implementation of googletest harder to maintain and more
71+ (otherwise we make the implementation of GoogleTest harder to maintain and more
7272error-prone than necessary).
7373
7474Historically, the `EXPECT_EQ()` macro took the *expected* value as its first
@@ -162,7 +162,7 @@ methods, the parent process will think the calls have never occurred. Therefore,
162162you may want to move your `EXPECT_CALL` statements inside the `EXPECT_DEATH`
163163macro.
164164
165- ## EXPECT_EQ(htonl(blah), blah_blah) generates weird compiler errors in opt mode. Is this a googletest bug?
165+ ## EXPECT_EQ(htonl(blah), blah_blah) generates weird compiler errors in opt mode. Is this a GoogleTest bug?
166166
167167Actually, the bug is in `htonl()`.
168168
@@ -199,7 +199,7 @@ const int Foo::kBar; // No initializer here.
199199```
200200
201201Otherwise your code is ** invalid C++** , and may break in unexpected ways. In
202- particular, using it in googletest comparison assertions (` EXPECT_EQ ` , etc) will
202+ particular, using it in GoogleTest comparison assertions (` EXPECT_EQ ` , etc) will
203203generate an "undefined reference" linker error. The fact that "it used to work"
204204doesn't mean it's valid. It just means that you were lucky. :-)
205205
@@ -225,7 +225,7 @@ cases may want to use the same or slightly different fixtures. For example, you
225225may want to make sure that all of a GUI library's test suites don't leak
226226important system resources like fonts and brushes.
227227
228- In googletest , you share a fixture among test suites by putting the shared logic
228+ In GoogleTest , you share a fixture among test suites by putting the shared logic
229229in a base test fixture, then deriving from that base a separate fixture for each
230230test suite that wants to use this common logic. You then use `TEST_F()` to write
231231tests using each derived fixture.
@@ -264,7 +264,7 @@ TEST_F(FooTest, Baz) { ... }
264264```
265265
266266If necessary, you can continue to derive test fixtures from a derived fixture.
267- googletest has no limit on how deep the hierarchy can be.
267+ GoogleTest has no limit on how deep the hierarchy can be.
268268
269269For a complete example using derived test fixtures, see
270270[sample5_unittest.cc](https:// github.com/google/googletest/blob/master/googletest/samples/sample5_unittest.cc).
@@ -278,7 +278,7 @@ disabled by our build system. Please see more details
278278
279279## My death test hangs (or seg-faults). How do I fix it?
280280
281- In googletest , death tests are run in a child process and the way they work is
281+ In GoogleTest , death tests are run in a child process and the way they work is
282282delicate. To write death tests you really need to understand how they work—see
283283the details at [ Death Assertions] ( reference/assertions.md#death ) in the
284284Assertions Reference.
@@ -305,8 +305,8 @@ bullet - sorry!
305305
306306## Should I use the constructor/destructor of the test fixture or SetUp()/TearDown()? {#CtorVsSetUp}
307307
308- The first thing to remember is that googletest does ** not** reuse the same test
309- fixture object across multiple tests. For each ` TEST_F ` , googletest will create
308+ The first thing to remember is that GoogleTest does ** not** reuse the same test
309+ fixture object across multiple tests. For each ` TEST_F ` , GoogleTest will create
310310a ** fresh** test fixture object, immediately call ` SetUp() ` , run the test body,
311311call ` TearDown() ` , and then delete the test fixture object.
312312
@@ -345,11 +345,11 @@ You may still want to use `SetUp()/TearDown()` in the following cases:
345345 that many standard libraries (like STL) may throw when exceptions are
346346 enabled in the compiler. Therefore you should prefer ` TearDown() ` if you
347347 want to write portable tests that work with or without exceptions.
348- * The googletest team is considering making the assertion macros throw on
348+ * The GoogleTest team is considering making the assertion macros throw on
349349 platforms where exceptions are enabled (e.g. Windows, Mac OS, and Linux
350350 client-side), which will eliminate the need for the user to propagate
351351 failures from a subroutine to its caller. Therefore, you shouldn't use
352- googletest assertions in a destructor if your code could run on such a
352+ GoogleTest assertions in a destructor if your code could run on such a
353353 platform.
354354
355355## The compiler complains "no matching function to call" when I use ASSERT_PRED* . How do I fix it?
@@ -375,7 +375,7 @@ they write
375375This is ** wrong and dangerous** . The testing services needs to see the return
376376value of ` RUN_ALL_TESTS() ` in order to determine if a test has passed. If your
377377` main() ` function ignores it, your test will be considered successful even if it
378- has a googletest assertion failure. Very bad.
378+ has a GoogleTest assertion failure. Very bad.
379379
380380We have decided to fix this (thanks to Michael Chastain for the idea). Now, your
381381code will no longer be able to ignore ` RUN_ALL_TESTS() ` when compiled with
@@ -440,14 +440,14 @@ TEST_F(BarTest, Abc) { ... }
440440TEST_F(BarTest, Def) { ... }
441441```
442442
443- ## googletest output is buried in a whole bunch of LOG messages. What do I do?
443+ ## GoogleTest output is buried in a whole bunch of LOG messages. What do I do?
444444
445- The googletest output is meant to be a concise and human-friendly report. If
446- your test generates textual output itself, it will mix with the googletest
445+ The GoogleTest output is meant to be a concise and human-friendly report. If
446+ your test generates textual output itself, it will mix with the GoogleTest
447447output, making it hard to read. However, there is an easy solution to this
448448problem.
449449
450- Since `LOG` messages go to stderr, we decided to let googletest output go to
450+ Since `LOG` messages go to stderr, we decided to let GoogleTest output go to
451451stdout. This way, you can easily separate the two using redirection. For
452452example:
453453
@@ -520,7 +520,7 @@ TEST(MyDeathTest, CompoundStatement) {
520520
521521## I have a fixture class `FooTest`, but `TEST_F(FooTest, Bar)` gives me error ``"no matching function for call to `FooTest::FooTest()'"``. Why?
522522
523- Googletest needs to be able to create objects of your test fixture class, so it
523+ GoogleTest needs to be able to create objects of your test fixture class, so it
524524must have a default constructor. Normally the compiler will define one for you.
525525However, there are cases where you have to define your own:
526526
@@ -545,11 +545,11 @@ The new NPTL thread library doesn't suffer from this problem, as it doesn't
545545create a manager thread. However, if you don't control which machine your test
546546runs on, you shouldn't depend on this.
547547
548- ## Why does googletest require the entire test suite, instead of individual tests, to be named *DeathTest when it uses ASSERT_DEATH?
548+ ## Why does GoogleTest require the entire test suite, instead of individual tests, to be named *DeathTest when it uses ASSERT_DEATH?
549549
550- googletest does not interleave tests from different test suites. That is, it
550+ GoogleTest does not interleave tests from different test suites. That is, it
551551runs all tests in one test suite first, and then runs all tests in the next test
552- suite, and so on. googletest does this because it needs to set up a test suite
552+ suite, and so on. GoogleTest does this because it needs to set up a test suite
553553before the first test in it is run, and tear it down afterwards. Splitting up
554554the test case would require multiple set-up and tear-down processes, which is
555555inefficient and makes the semantics unclean.
@@ -588,11 +588,11 @@ TEST_F(FooDeathTest, Uvw) { ... EXPECT_DEATH(...) ... }
588588TEST_F(FooDeathTest, Xyz) { ... ASSERT_DEATH(...) ... }
589589```
590590
591- ## googletest prints the LOG messages in a death test's child process only when the test fails. How can I see the LOG messages when the death test succeeds?
591+ ## GoogleTest prints the LOG messages in a death test's child process only when the test fails. How can I see the LOG messages when the death test succeeds?
592592
593593Printing the LOG messages generated by the statement inside `EXPECT_DEATH()`
594594makes it harder to search for real problems in the parent's log. Therefore,
595- googletest only prints them when the death test has failed.
595+ GoogleTest only prints them when the death test has failed.
596596
597597If you really need to see such LOG messages, a workaround is to temporarily
598598break the death test (e.g. by changing the regex pattern it is expected to
@@ -611,7 +611,7 @@ needs to be defined in the *same* name space. See
611611
612612## How do I suppress the memory leak messages on Windows?
613613
614- Since the statically initialized googletest singleton requires allocations on
614+ Since the statically initialized GoogleTest singleton requires allocations on
615615the heap, the Visual C++ memory leak detector will report memory leaks at the
616616end of the program run. The easiest way to avoid this is to use the
617617`_CrtMemCheckpoint` and `_CrtMemDumpAllObjectsSince` calls to not report any
@@ -625,7 +625,7 @@ things accordingly, you are leaking test-only logic into production code and
625625there is no easy way to ensure that the test-only code paths aren't run by
626626mistake in production. Such cleverness also leads to
627627[Heisenbugs](https://en.wikipedia.org/wiki/Heisenbug). Therefore we strongly
628- advise against the practice, and googletest doesn't provide a way to do it.
628+ advise against the practice, and GoogleTest doesn't provide a way to do it.
629629
630630In general, the recommended way to cause the code to behave differently under
631631test is [Dependency Injection](http://en.wikipedia.org/wiki/Dependency_injection). You can inject
@@ -672,7 +672,7 @@ TEST(CoolTest, DoSomething) {
672672```
673673
674674However, the following code is ** not allowed** and will produce a runtime error
675- from googletest because the test methods are using different test fixture
675+ from GoogleTest because the test methods are using different test fixture
676676classes with the same test suite name.
677677
678678``` c++
0 commit comments