What is your favorite / recommended project structure and file structure for Unit Testing using Boost?

I have not used Unit Testing yet, and I intend to accept this procedure. I was impressed with TDD and of course I want to try, I'm pretty sure this is the way to go.

Boost looks like a good choice, mainly because it is supported. With that said, how should I implement a working and elegant file structure and project structure? I am using VS 2005 in Win XP. I searched for this topic and was more confused than enlightened.

+6
c ++ boost unit-testing tdd visual-studio
source share
2 answers

Our test structure, based on Boost, is as follows:

ProjectRoot/ Library1/ lib1.vcproj lib1.cpp classX.cpp ... Library2/ lib2.vcproj lib2.cpp toolB.cpp classY.cpp ... MainExecutable/ main.cpp toolA.cpp toolB.cpp classZ.cpp ... Tests/ unittests.sln ut_lib1/ ut_lib1.vcproj (referencing the lib1 project) ut_lib1.cpp (with BOOST_AUTO_TEST_CASE) - testing public interface of lib1 ut_classX.cpp - testing of a class or other entity might be split into a separate test file for size reasons or if the entity is not part of the public interface of the library ... ut_lib2/ ut_lib2.vcproj (referencing the lib2 project) ut_lib2.cpp (with BOOST_AUTO_TEST_CASE) - testing public interface of lib2 ... ut_toolA/ ut_toolA.vcproj (referencing the toolA.cpp file) ut_toolA.cpp - testing functions of toolA ut_toolB/ ut_toolB.vcproj (referencing the toolB.cpp file) ut_toolB.cpp - testing functions of toolB ut_main/ ut_main.vcproj (referencing all required cpp files from the main project) ut_classZ.cpp - testing classZ ... 

This structure was chosen for an old project, where we had to make individual decisions about which tests to add and how to group test projects for existing source code modules.

Notes:

  • A single test code is always compiled separately from the production code.
  • Production projects do not reference unit testing code.
  • Unit testing projects include source files directly or only reference libraries, depending on what makes sense given the use of a particular code file.
  • Unit tests are performed using the post-build step in each ut _ *. vcproj
  • All our production assemblies automatically run unit tests as well. (In our build scripts.)

In our real (C ++) world, you need to compromise with each other. obsolete problems, developer convenience, compilation time, etc. I think our project structure is a good compromise. :-)

+2
source share

I spilled my main code on .libs or .dll, and then my Boost testing projects depend on these lib / dll projects. Therefore, I could:

 ProjectRoot Lib1Source Lib1Tests Lib2Source Lib2Tests 

An alternative is to save the source in a separate folder and add files to the main application project and unit test project, but I find this a bit dirty. YMMV.

0
source share

All Articles