I am interested in hearing about experiences using TDD and unit testing for C++ in general with Visual Studio 2005 (Professional)
First some background. We have a fairly large project and much of it has been developed on Linux using CppUnit for the unit tests. The project is divided into several libraries, each with their own set of tests. I have a simple script which compiles the library, compiles the test suite and then runs the tests. So after making changes in the code I just run "test" from a command line and the tests run.
Now, most of the developers are using Visual Studio 2005 on Windows for the development of this product. Of course they can still run the tests from a command line using nmake but involves extra steps and I would prefer to have a much more integrated solution.
So my question has two parts.
Firstly, what is the best way of laying out the code for tests on a large code base? Is it normal to create several test projects in a solution, one for each library?
Secondly are there any tools for integrating CppUnit tests into Visual Studio? With dependencies set up corectly running the test project should run the tests but currently the results still appear in a command window.
One of the projects at my company does exactly this. We use a unit test framework called CXXTest (http://cxxtest.sourceforge.net/guide.html). We really like this framework for C++ because it only requires that you write a header file that contains your unit tests. The .CPP files are created by a script (both Python and Perl scripts are provided).
We integrate with visual studio by providing a post build step that builds the unit tests (if they need building) and then executes them. The output (showing what passed and what failed) is displayed in the output window -- you never need to leave the IDE.
I use the Boost Test framework. I tend to split my code into .lib files and will have a separate console-mode EXE test project for each. When the test project is built it makes use of the 'Post build stage' to launch itself, thus running the tests. You could make each test project a dependency of your main application so that each time it builds, all tests are run first, but this can be time-consuming. Instead I tend to run the test projects by hand as needed, but my automated nightly build system will run all test projects as a matter of course (I script this and if any tests fail, the build fails and I get an email notification).
More details here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With