Hi, does anybody know how to write unit tests for private functions? I have seen on the web that it should be possible to define private public before you include your test class, but that has only worked for members and not functions...
I.e.
#define private public
#include "testclass.h"
Any ideas?
Our customer requires that x% of the code is tested and that isn't possible to reach if we only write tests for public functions.
Thanks in advance.
Don't know if it'd help (or what it costs, but): Digia Quality Kit: http://www.digia.com/digia/devhome.nsf/pages/Enabling+Technologies
You could make unit testing class as a friend class of tested class. Of course this is not the most elegant solution and your customer may have some negative thoughts about it...
Anyways something like this:
class CFiiFaa: public CBase
{
.
.
.
#ifdef __UNITTEST_
friend class CFiiFaaTest;
#endif
};
Thanks lutku, that is actually the way we are doing it now. And as far as I know that seems to be the only way to accomplish it...But in case you have any other ideas I would gladly hear them.
/nijansso