Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you integrate a TDD approach with VisualStudio?

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.

like image 754
David Dibben Avatar asked Sep 21 '08 14:09

David Dibben


3 Answers

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.

like image 81
Steve Hawkins Avatar answered Nov 11 '22 18:11

Steve Hawkins


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.

like image 29
Rob Avatar answered Nov 11 '22 20:11

Rob


  • I find the following folder hierarchy useful. Create code and tests as the subfolders of ProjectFolder. Create 2 solutions code\Project.sln and tests\Tests.sln. Now for every class library or executable created, e.g. Customers.dll have a corresponding test dll. So code\Customers\Customers.csproj will have tests\Customers\TestCustomers.csproj, which references the former.
  • Integrating CPPUnit into Visual Studio would be on the lines of choosing the right application in Project Properties.. 'Debug' settings. I think this page has what you need to have single key press test execution + reporting within the IDE.
like image 2
Gishu Avatar answered Nov 11 '22 19:11

Gishu