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:

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:

Step 2, Write Production code to pass the failing tests.

The code from first step will fail during compilation, so the next step is to add the production code such that we can compile and pass the test:

Now this will give us a test failure:

and by adding more production code:

this will pass the test.

Step 3, Refactor the production code

step 3 is refactoring, by doing refactoring we can clean our code to this:

Now we have to jump step1 again, add more test and continue.

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x