0

I would like to try using a unit testing framework for testing the code that I write in C, C++ or sometimes IEC languages too.

So my question is - is there some big limitation using C-written unit test Framework for testing C++ code that would restrain me from using it?


Background info: I tried a variety of frameworks available as opensource - that are written in C / C++. And finally I concluded that 'embedded unit' - written in C and 'CppTest' - written in C++ were the candidates (mainly because the testing has to be performed on an embedded platform). But before selecting the winner I fell into this very Basic question . And to my knowledge I find no big limitations. Except that: In C++ Unit testing framework:I can make the testClass a friend of testable class and test its private attributes/ functions (which is not really important for me). sorry if this is a silly question - i just started exploring the world of testing.

7
  • The code as in "program code" is used as mass noun. So it is "code", not "codes". Commented Feb 27, 2013 at 15:17
  • What's your problem using a unit testing framework written in C++ for testing C code? I'm doing this using gtest, and it works fine for me ... Commented Feb 27, 2013 at 15:17
  • See here for more info stackoverflow.com/questions/91384/… Commented Feb 27, 2013 at 15:18
  • If your concern is that you want to run your unit tests on a resource limited embedded target, you should make this clear in your question. But I have also brought gtest running on a (not so resource limited) embedded platform. Commented Feb 27, 2013 at 15:20
  • @g-makulik I didn't say I face problems using C++ written unit testing framework. Also I didn't face problem running cpptest / embeddedunit in my highly resource limited customised embedded platform. My question is exactly what I have mentioned above - with no offense :) Commented Feb 27, 2013 at 15:34

1 Answer 1

3

One example is that you will be hard pushed to test expected C++ exceptions generated by your code under test using a strict C framework. I am sure there are other holes in this approach, but it depends on your C++ code.

Unless you have a really good reason, CppTest seems like the logical choice of your two candidates. I've linked in comments to a question that might cover options you have missed.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I did try few options including (CppUnit,CxxTest,CppTest,Catch,Fructose,Cutest,Cute,testape,maestra,easyunit,cut,gtest,cpputest,yaffut). And CppTest and embedded unit were the candidates mainly because of the embedded platform (our own IDE, RTOS and Hardware(PLC)) limitations.
@SteveTownsend, as long as the 'C'-like unit test function is compiled in C++, then the OP should be able to try/catch within the unit test function?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.