Question

I'm getting started with Boost::Test driven development (in C++), and I'm retrofitting one of my older projects with Unit Tests. My question is -- where do I add the unit test code? The syntax for the tests themselves seems really simple according to Boost::Test's documentation, but I'm confused as to how I tell the compiler to generate the executable with my unit tests. Ideally, I'd use a precompiled header and the header-only version of the boost::test library.

Do I just create a new project for tests and add all my existing source files to it?

Billy3

Was it helpful?

Solution

They way I've added Boost unit tests to existing solutions was to create new projects and put the test code in those projects. You don't need to worry about creating a main() function or setting up the tests. Boost takes care of all that for you.

Here is a project I put on Google Code that uses Boost for its unit tests.

OTHER TIPS

You can put your tests to the same project, but mark files with tests as Excluded from Build for Release and Debug configuration and create new project configuration for unit tests. Here is an article about using Boost Test in Visual Studio.

We don't have boost test but use cppunit but this should be pretty general. We have very thin main project (basically only consisting of main.cpp) all the other files are in libraries (mostly static for us). The test code links against these libraries and includes what ever it needs per test. This also keeps you from having to have all the applications code included in the test project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top