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.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
  • [The code as in "program code" is used as mass noun. So it is "code", not "codes".](http://english.stackexchange.com/questions/20455/is-it-wrong-to-use-the-word-codes-in-a-programming-context) –  Feb 27 '13 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 ... – πάντα ῥεῖ Feb 27 '13 at 15:17
  • See here for more info http://stackoverflow.com/questions/91384/unit-testing-for-c-code-tools-and-methodology#92569 – Steve Townsend Feb 27 '13 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. – πάντα ῥεῖ Feb 27 '13 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 :) –  Feb 27 '13 at 15:34
  • Are you compiling with C++? If so, then it is C++ code? I wouldn't anticipate any problems, as long as you are happy writing your tests in a 'C' like subset of C++. – Josh Petitt Feb 27 '13 at 17:16
  • BTW, I've used the following for embedded. Its pure C and I use it for C code, so maybe not applicable to your situation, but I didn't see it in your list. https://github.com/ThrowTheSwitch/Unity/ – Josh Petitt Feb 27 '13 at 17:19

1 Answers1

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.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
  • 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. –  Feb 27 '13 at 15:29
  • @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? – Josh Petitt Feb 27 '13 at 17:18