Writing and invoking tests with Google Test
In the previous recipe, we had a glimpse of what it takes to write simple tests with the Google Test framework. Multiple tests can be grouped into a test suite and one or more test suites grouped into a test program. In this recipe, we will see how to create and run tests.
Getting ready
For the sample code in this recipe, we'll use the point3d
class we discussed in the Writing and invoking tests with Boost.Test recipe.
How to do it...
Use the following macros to create tests:
TEST(TestSuiteName, TestName)
defines a test calledTestName
as part of a test suite calledTestSuiteName
:TEST(TestConstruction, TestConstructor) { auto p = point3d{ 1,2,3 }; ASSERT_EQ(p.x(), 1); ASSERT_EQ(p.x(), 2); ASSERT_EQ(p.x(), 3); } TEST(TestConstruction, TestOrigin) { auto p = point3d::origin(); ASSERT_EQ(p.x(), 0); ASSERT_EQ(p.x(), 0); ASSERT_EQ(p.x(), 0); }
TEST_F(TestSuiteWithFixture...