User forums > Using Code::Blocks

Using CodeBlocks projects with unit testing.

(1/3) > >>

Slix:
I'm starting to unit test some of the code in my coding project, but I'm not sure how to set up the project files to make unit testing work.

I created a test project file in the root folder of my coding project, and I'm put the unit testing .cpp files in the test subfolder. (I'm using UnitTest++, but the advice here will probably apply to any unit testing framework.) Do I have to add all of my base project's headers and .cpp files (except the one with int main()) to the test project too? Also, how do I make it so that every time I build my base project, it also runs the unit tests?

Thanks!

EDIT: I am making a library, so that might make things simpler. However, I'd still like to know how to do this with console programs and stuff.

oBFusCATed:
http://wiki.codeblocks.org/index.php?title=UnitTesting

Slix:

--- Quote from: oBFusCATed on July 22, 2010, 09:14:39 am ---http://wiki.codeblocks.org/index.php?title=UnitTesting

--- End quote ---

I have already read that, oBFusCated. Unfortunately, it doesn't explain my question at all. It explains a lot about using unit testing with Code::Blocks, but it doesn't explain how to make your project work with it. The setup that the wiki explains only applies if you are making a project for ONLY unit testing. It doesn't explain how to set up two projects (one for your main project, one for your unit tests). The wiki uses one project file with a main() dedicated to unit testing, which isn't practical.

killerbot:
this is quit simple, the wiki article describes on how to do it though, but you are right it doesn't show an example.

Typically your classes will be packaged in a library (static or dynamic), and in the end your application will use one or more libraries and will link with those libraries.

Well a unit test is nothing more then another application using one or more libraries (preferably only the one under test).

So in your unit test application add the include directory of your library, and link with the deliverable of the library project (aka the library binary).

So basically take the same approach as you would do when you have an application using a library.

oBFusCATed:
Slix:
The approach I take is a bit different, I don't create static/dynamic libraries. I just create the unit testing project then add all test_*.cpp files that do the tests, then I fix all undefined symbol errors by adding the relevant .cpp files.
This way I can set the unittest project as a dependency of the project I'm testing and when I build the main project the unit test project is build and the tests are run.

Navigation

[0] Message Index

[#] Next page

Go to full version