Menu

ASSERT -> CPPUNIT_ASSERT

Help
2004-07-13
2004-07-20
  • Nicolas Gendron

    Nicolas Gendron - 2004-07-13

    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

     
    • Nicolas Gendron

      Nicolas Gendron - 2004-07-13

      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?

       
    • Anthon Pang

      Anthon Pang - 2004-07-20

      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).

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.