Menu

About CPPUNIT_ASSERT_EQUAL()

Help
otmane
2007-04-20
2013-04-22
  • otmane

    otmane - 2007-04-20

    Hello every one, I begin programming with the cppunit framework and i have a problem, here is my code
    Code------------------------------
    void OpNotTest::normalCaseTest(){
      CPPUNIT_ASSERT_EQUAL(1, 3);
      CPPUNIT_ASSERT_EQUAL(1, 1);
      CPPUNIT_ASSERT_EQUAL(1, 4);

    }
    ---------------------------------

    When I test this function the result are :
    Tests Result-------------------------
    OpNotTest.cpp:73:Assertion
    Test name: OpNotTest::normalCaseTest
    equality assertion failed
    - Expected: 1
    - Actual  : 3
    -------------------------------------

    The runing test stop in the first Failure! I want him to continue at the end of the function. And for a particular reason
    I can't separate the 3 assetion, because my function will contain in the future many assertion.

    Thank's for the helper

     
    • Code Guru

      Code Guru - 2007-04-20

      Perhaps you are trying to test too many things at once.  Your contrived example should be split up into three separate tests:
      [code]
      void OpNotTest::test1(){
        CPPUNIT_ASSERT_EQUAL(1, 3);
      }

      void OpNotTest::test2(){
        CPPUNIT_ASSERT_EQUAL(1, 1);
      }

      void OpNotTest::test3(){
        CPPUNIT_ASSERT_EQUAL(1, 4);
      }

      This way you will see each assertion pass or fail.

      When an assertion fails, it typically signals a bad state of the software system.  Any assertions that succeed afterward are misleading since the state or input is possibly bad.

      Of course, the above example is contrived, so perhaps we can get a better idea of what you want to do if you post some of your real code.

       
    • otmane

      otmane - 2007-04-23

      Thank's for the replay,
      I explain to you what i want to do.

      I have a class , OpNotTest that contain tree Test function :
      void normalCaseTest();
      void outPutForcingTest();
      void robustnessTest();

      These functions used a function : bool IsEqual(char *image1, char * image2) to test if the two images are the same

      Example of use :

      void OpNotTest::normalCaseTest(){
          applyOperator(NC1_1, "NotResult.inr.gz");
          CPPUNIT_ASSERT(IsEqual(NC_RES1_1, "NotResult.inr.gz"));

          applyOperator(NC1_2, "NotResult.inr.gz");
          CPPUNIT_ASSERT(IsEqual(NC_RES1_2, "NotResult.inr.gz"));
      }

      So What I want to do is to test all the result of the function  applyOperator() by the func. IsEqual() that's why I used CPPUNIT_ASSERT(). And i don't wnat that the program crash whitout terminating all the tests with IsEqual().

      I hope that you have a better idea now of what i want to do.

       
      • Code Guru

        Code Guru - 2007-04-29

        CppUnit is not designed to do what you describe.  In fact, it sounds like you are trying to group several tests into one method.  You need to separate these tests into several different methods as I described earlier.  Typically, you should have only one CPPUNIT_ASSERT_XXX call per test method.  The typical convention for grouping related tests is by putting them in a class.  So perhaps you can make NormalOpNotTest, OutputForcingOpNotTest, and RobustnessOpNotTest classes with each of the appropriate test methods in each class.  This is the way CppUnit is designed to handle a situation like you describe.

         
    • otmane

      otmane - 2007-04-27

      Okay, I see no one to help here! Not much documentation about CppUnit, no advanced example too...
      I don't now why, but I think no one comes here to read our MSG !!

       

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.