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 case and one or more test cases grouped into a test program. In this recipe, we will see how to create and run tests.
For the sample code in this recipe, use the point3d
class discussed in the Writing and invoking tests with Boost.Test recipe.
Use the following macros to create tests:
TEST(TestCaseName, TestName)
defines a test calledTestName
as part of a test case calledTestCaseName
:
TEST(TestConstruction, TesConstructor) { 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); ...