If, for example, I have some ASSERT in the code I want to test to check some pre-conditions.
It is possible to replace ASSERT for CPPUNIT_ASSERT
during unit-testing ?
It don't seems to work for me, #undef ASSERT seems to work only in the .cpp file I want to test and I can't redefine it as #define ASSERT(x) CPPUNIT_ASSERT(x)
The best for me is to make all needed changes outside the "non-testing" code.
Any Idea?
Thanks
Nic
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So these redefined ASSERT()'s are appearing in your application source files (and not in your unit test files)? On the surface, it looks like a reasonable workaround.
I suspect you can trim your solution down since the ASSERT macro would have to be defined elsewhere to avoid compilation errors when UNIT_TESTING is undefined.
And if it turns out that *you* are defining the ASSERT macro elsewhere, then you can probably move this macro to that header file (or its own).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If, for example, I have some ASSERT in the code I want to test to check some pre-conditions.
It is possible to replace ASSERT for CPPUNIT_ASSERT
during unit-testing ?
It don't seems to work for me, #undef ASSERT seems to work only in the .cpp file I want to test and I can't redefine it as #define ASSERT(x) CPPUNIT_ASSERT(x)
The best for me is to make all needed changes outside the "non-testing" code.
Any Idea?
Thanks
Nic
Answer to myself :-D :
It is possible if I define a preprocessor macro like UNIT_TESTING and if I'm doing :
#ifdef UNIT_TESTING
#ifdef ASSERT
#undef ASSERT
#endif
#include <cppunit/TestAssert.h>
#define ASSERT(x) CPPUNIT_ASSERT(x)
#endif
It is the only way I found to change as less as possible my application files.
Any other ideas?
So these redefined ASSERT()'s are appearing in your application source files (and not in your unit test files)? On the surface, it looks like a reasonable workaround.
I suspect you can trim your solution down since the ASSERT macro would have to be defined elsewhere to avoid compilation errors when UNIT_TESTING is undefined.
And if it turns out that *you* are defining the ASSERT macro elsewhere, then you can probably move this macro to that header file (or its own).