https://github.com/google/googletest/tree/master/googletest/docs
https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
https://code.google.com/p/googletest-translations/wiki/GoogleTestPrimerRussian
https://github.com/google/googletest/blob/master/googletest/docs/V1_7_Primer.md
https://github.com/google/googletest/blob/master/googletest/docs/primer.md
Statements
EXPECT_FLOAT_EQ
ASSERT_FLOAT_EQ
EXPECT_DOUBLE_EQ
ASSERT_DOUBLE_EQ
Assertion Types
Tests
Simple Test
TEST(TestSuiteName, TestName) { ... test body ... }
Fixture Test
class QueueTest : public ::testing::Test { protected: void SetUp() override { q1_.Enqueue(1); q2_.Enqueue(2); q2_.Enqueue(3); } // void TearDown() override {} Queue<int> q0_; Queue<int> q1_; Queue<int> q2_; };
// For each TEST_F() test googletest will: // 1. Create a fresh test fixture at runtime // 2. Call SetUp() // 3. Run the test // 4. Clean up by calling TearDown() // 5. Delete the test fixture
TEST_F(QueueTest, IsEmptyInitially) { EXPECT_EQ(q0_.size(), 0); }
int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_death_test_style = "fast"; return RUN_ALL_TESTS(); }
Command-line examples (https://github.com/google/googletest/blob/master/googletest/docs/advanced.md):
./foo_test It has no flag and thus runs all its tests.
./foo_test --gtest_filter=* Also runs everything, due to the single match-everything * value.
./foo_test --gtest_filter=FooTest.* Runs everything in a test suite FooTest .
./foo_test --gtest_filter=*Null*:*Constructor* Runs any test whose full name contains either "Null" or "Constructor" .
./foo_test --gtest_filter=-*DeathTest.* Runs all non-death tests.
./foo_test --gtest_filter=FooTest.*-FooTest.Bar Runs everything in the test suite FooTest except FooTest.Bar.
./foo_test --gtest_filter=FooTest.*:BarTest.*-FooTest.Bar:BarTest.Foo Runs everything in the test suite FooTest except FooTest.Bar and everything in the test suite BarTest except BarTest.Foo.
Notes
1. Filter setup via command-line has priority over filter setup via source code