Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginning Code::blocks and UnitTest++

I'm about to start a C++ project but I'm stuck at the basics.

I want to use the (linux) Code::Blocks IDE, and it's easy to create a normal project. However I want to do TDD using the UnitTest++ framework, and I don't know how to set everything up cleanly.

I've already asked a question about where to put the UnitTest::RunAllTests() command, and they told me the best place is the main() of a separate program.

How do I go about doing this in Code::Blocks? I think I need to create 2 projects:

  • The "real" project with its own main();
  • The unit testing project containing the tests and the main() with UnitTest::RunAllTests() inside.

Then somehow have the first project build and run the second during its build process. I don't know how to do that yet but I can find out on my own.

My questions are:

  1. this is the right method?
  2. do I have to create also a project for the UnitTest++ framework, in order to let other people build it on other platforms? Or is dropping the complied library in the project's path enough?
  3. how can I organize the directories of these projects together? It'd be nice to put the tests related to each package in the same directory as that package, but is it ok to have multiple projects in the same directory tree?
like image 591
Marco Giancotti Avatar asked Sep 18 '11 16:09

Marco Giancotti


1 Answers

I'll partly answer my own questions, as I've managed to get everything working.

  1. Following the instructions on the official documentation page, I've put the UnitTest++ folder with the compiled library and all the source files in my project's path.
  2. Then I created a test project for all the unit testing, with a main function containing the famous UnitTest::RunAllTests(). I put $exe_output as a post-build process here, in order to have the tests executed automatically every time I build this project.
  3. I created the "real" project where my code to be tested will go. In the build settings I specified the test project as a dependency of the real project, so that every time I build the real one, it also builds the test project first.

With these settings I can work on my tests and on the real code, and I only have to build the real one to have the updated tests executed. Any failing test will also make the build fail.

Now two questions remain: "is this the best approach?" and "right now each project lives in a different directory. Is it wiser to leave it this way or should I put each test in the same folder as the real code to be tested?"

like image 124
Marco Giancotti Avatar answered Oct 23 '22 04:10

Marco Giancotti