Example of Test Driven Development with C++ and Google Test
To develop a software based on “Test Driven Development” one should follow the following steps:
1 2 3 4 |
1)Write enough failing Test Code (include compile time and run time failures) 2)Write Production code to pass the failing tests. 3)Refactor the production code and verify the same with existing test. 4)Go to step 1 |
so let say we want to develop a binary search tree, here I’m using Google Test. Step 1, Write enough failing Test Code so the first step would be something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
class testingTree: public ::testing::Test { protected: testingTree(){} ~testingTree(){} void SetUp(){} void TearDown(){} }; TEST_F(testingTree,makeTree) { std::shared_ptr<Tree> tree=makeTree(); EXPECT_NE(tree.get(),nullptr); } int main(int argc, char ** argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } |
Step 2, Write Production code to […]
Example of Test Driven Development with C++ and Google Test Read More »