Page 1 of 3
I find it surprising how little I actually hear about XP programming and Test Driven Development (TDD). I'm not going to go in depth about the subject of TDD but I will share my thoughts and give a step-by-step guide on how to setup a cxxtest project that makes doing TDD with c++ easier than ever. For more information about TDD you can look at Games from Within. Noel Lopis goes very in-depth on the subject and has a lot of information about the different solutions available.
I personally became interested in TDD when I noticed that even after a couple of years using the same base code for my personal projects I was still finding errors. I remember thinking that there has to be a way to ensure code works to specs.
I have had cases in the past, as I'm sure most people have, where I would run some form of tests on some specific code. In my case it was testing what performance boost can be achieved by adding a memory manager to a link list class. I remember creating the console application, writing the tests and then writing a bunch of output that would tell me what was going on. The more I wanted the test to say the more output code I would have to write. I didn't continue doing it because it was such a hassle to write the test and especially to write the output.
So I looked... and looked... and looked. It's kind of surprising to find out that both C# and Java have very solid open source unit testing environments, NUnit and JUnit respectively. There were a couple others for C# and Java, but there is no real reason to even consider them.
I found a lot of different testing suites for C++, but none of them really stood out. I was about to start testing all of the different testing environments when I stumbled on Noel's website. His articles led me to choose cxxtest. I picked it because of its simplicity, customizability and portability.
There were only two problems I found with it. The first was that it's not really supported, though after using it for a bit there's no real reason to keep supporting it. It's very solid and easy to use. The second problem was that the examples showed that you needed three (3!) projects for it to work properly. I fixed it quite easily using Visual Studio.Net by simply adding some pre and post build steps to a single project.
After using it for a bit I also found some very neat ways to expand upon it that I'll share as well. Enough of all the words time for some meat.
- Details
- Written by Chris Savoie
- Category: Articles
- Hits: 7962