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".
Boost has an excellent unit test library.
cppunit is what we use.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With