views:

159

answers:

6

Possible Duplicates:
Suggestion for UnitTest tools for C++
Choosing a C++ unit testing tool/framework
Unit Testing C Code

This is something I've been wondering now that we have to use C/C++ as base language for some of our university projects :

In Java there's JUnit,

In PHP there's PHPUnit

etc.

How are unit testing done in C/C++? This is probably a silly question, but I don't think I ever read exactly how applications (source code) are unit tested--if there's even such a thing in C/C++--other than "check if the code compiles".

+3  A: 

Boost has an excellent unit test library.

Sam Miller
+1  A: 

cppunit is what we use.

dicroce
+1  A: 

There are quite a few frameworks but to name a few:

Some people will just role their own using #ifdefs and a single test.c or test.cpp file:

#ifdef TEST_1
int main(int argc, char** argv) { /*test code for 1*/ }
#endif

#ifdef TEST_2
int main(int argc, char** argv) { /*test code for 2*/ }
#endif

At compile time a you can generate the test by defining TEST_x (where x is a number) this generates executables for each test. Maybe not ideal but very simple.

Evan
A: 

I've used CxxTest and CppUnit and found CxxTest to be easier to use (it automates generating some of the skeleton code - on the downside it needs Python installed) and lightweight (no libraries, entirely header based).

Eugen Constantin Dinca
+1  A: 

We use cunit:

http://cunit.sourceforge.net/

It allows one to logically (or functionally) group tests, produce test output in XML format for automated publishing of results, etc.

Misk
+1  A: 

anther one is UnitTest++. Header-only, lightweight and simple operation, yet does everything needed.

stijn