::testing::Test — GTest Fixture
Base class for Google Test fixtures, providing automatic setup and teardown for each test. Inherit from it to create a fixture that shares member variables and helper functions across multiple tests. SetUp() runs before each test, TearDown() runs after each test — both are automatically called by Google Test. ::testing::UnitTest::current_test_info()
Returns a pointer to information about the currently running test. Contains details like the test name, test suite name, and whether the test has failed. Commonly used in SetUp() to get the test name for creating unique temporary files or directories. EXPECT_TRUE
A Google Test macro that checks if a condition is true and marks the test as failed if it isn't. Unlike ASSERT_TRUE, the test continues running after a failure so other checks can still be evaluated. Use when you want to collect multiple failures in one test run rather than stopping at the first one. EXPECT_LT
A Google Test macro that checks if the first value is less than the second, marking the test as failed if it isn't. Unlike ASSERT_LT, the test continues running after a failure so other checks can still be evaluated. Commonly used to verify something happened quickly or within a time limit. |
::testing::Test::SetUp()
A virtual function inherited from ::testing::Test that runs automatically before each individual test. Override it to initialise member variables, create temporary files, or prepare any state needed by the tests. Always paired with TearDown() to clean up anything created here. ::testing::UnitTest::GetInstance()
Returns a pointer to the single global instance of the UnitTest object. Uses the Singleton pattern — only one instance ever exists, and this method is how you access it. From it you can retrieve information about the currently running test suite and individual tests. ASSERT_TRUE
A Google Test macro that checks if a condition is true and immediately aborts the test if it isn't. Use when the rest of the test cannot meaningfully continue if this check fails. Contrast with EXPECT_TRUE which marks the test as failed but allows it to keep running. EXPECT_EQ
A Google Test macro that checks if two values are equal and marks the test as failed if they aren't. Unlike ASSERT_EQ, the test continues running after a failure so other checks can still be evaluated. Prints both the expected and actual values in the failure message making it easy to diagnose. |
testing::Test::TearDown()
A virtual function inherited from ::testing::Test that runs automatically after each individual test. Override it to clean up anything created in SetUp() — delete temporary files, restore environment variables, free resources. Always runs even if the test fails, ensuring cleanup always happens. TEST_F
Defines a test that uses a fixture class, giving it access to the fixture's member variables and helper functions. Google Test automatically calls SetUp() before the test and TearDown() after, with a fresh fixture instance each time. The second argument is the test name, which must be unique within the fixture. EXPECT_FALSE
A Google Test macro that checks if a condition is false and marks the test as failed if it isn't. Unlike ASSERT_FALSE, the test continues running after a failure so other checks can still be evaluated. Use when you want to verify something does not exist or did not happen. EXPECT_NE
A Google Test macro that passes when two values are not equal, and marks the test as failed if they are equal. Unlike ASSERT_NE, the test continues running after a failure so other checks can still be evaluated. Commonly used to verify a search or find operation returned a valid result. |
Cheatography
https://cheatography.com
C++ (Gtest) Cheat Sheet (DRAFT) by blakecromar
A cheat sheet on the Google test library.
This is a draft cheat sheet. It is a work in progress and is not finished yet.