Menu

Assertion Messages not showing.

Help
2008-04-24
2013-04-22
  • Brandon Miller

    Brandon Miller - 2008-04-24

    I'm making an assertion as follows:

    CPPUNIT_NS::Message cpputMsg_("Error :(");
    CPPUNIT_NS::Asserter::fail( cpputMsg_,
                    CPPUNIT_SOURCELINE() );

    But, in the output window, it only says...

    Test::testBlahBlah : assertion

    Why no descriptive message?

    I'm running this on a Win32 machine and have compiled the source for 1.12 successfully
    with Visual Studio .net 2003.

     
    • Andre Pinto

      Andre Pinto - 2008-04-24

      Hey Brandon,

      Try the CPPUNIT_ASSERT_MESSAGE macro, it takes the message and the condition and then, if the test fails the message is displayed.

       
    • Brandon Miller

      Brandon Miller - 2008-04-24

      Nope...nothing, none of the macros are displaying the message.  I do a stack trace through the calls, but it doesn't look like it's setting "m_message" to mine.  It is being set to "m_shortDescription" which in return is set to a empty string.

      I'm just not quite sure why it's not setting the message I pass in, am I setting it wrong?  I'll post the program below as it's just a snippet from the web and not my own code. 

      #include "stdafx.h"
      #include <iostream>

      #include <cppunit/TestRunner.h>
      #include <cppunit/TestResult.h>
      #include <cppunit/TestResultCollector.h>
      #include <cppunit/extensions/HelperMacros.h>
      #include <cppunit/BriefTestProgressListener.h>
      #include <cppunit/extensions/TestFactoryRegistry.h>

      class Test : public CPPUNIT_NS::TestCase
      {
        CPPUNIT_TEST_SUITE(Test);
        CPPUNIT_TEST(testHelloWorld);
        CPPUNIT_TEST_SUITE_END();

      public:
        void setUp(void) {}
        void tearDown(void) {}

      protected:
         
          void testHelloWorld(void)
          {
              CPPUNIT_NS::Message cpputMsg_("expected exception no thrown");
              cpputMsg_.addDetail (std::string ("What? "));
              CPPUNIT_ASSERT_MESSAGE ("failed", "1" == "2");  //  Tried passing in cpputMsg_ as well, no luck!
          }
         
      };

      CPPUNIT_TEST_SUITE_REGISTRATION(Test);

      int main( int ac, char **av )
      {
        //--- Create the event manager and test controller
        CPPUNIT_NS::TestResult controller;

        //--- Add a listener that colllects test result
        CPPUNIT_NS::TestResultCollector result;
        controller.addListener( &result );       

        //--- Add a listener that print dots as test run.
        CPPUNIT_NS::BriefTestProgressListener progress;
        controller.addListener( &progress );     

        //--- Add the top suite to the test runner
        CPPUNIT_NS::TestRunner runner;
        runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
        runner.run( controller );
       
        getchar();

        return 0;
      }

       
    • Andre Pinto

      Andre Pinto - 2008-04-28

      Instead of using those MACROS, try to use the code below :

      int main()
      {
         CPPUNIT_NS::TestResult controller;   
         CPPUNIT_NS::TestResultCollector result; // Add a listener that colllects test result   
         CPPUNIT_NS::BriefTestProgressListener progress;
         CPPUNIT_NS::TestSuite *pSuite;

         test->setSuite(pSuite);

         CPPUNIT_NS::TestRunner runner;
         controller.addListener( &result );        
         controller.addListener( &progress );

         runner.addTest(pSuite);
         runner.run( controller );
       
      }

      class test : public CPPUNIT_NS::TestCase

        void test::setSuite(CppUnit::TestSuite *suite)
      {
          suite->addTest(new CppUnit::TestCaller<test>
              (" test::FuncTest(void)",&test::FuncTest ));
      }

      void FuncTest()
      {
        bla bla bla

        CPPUNIT_ASSERT_MESSAGE("teste", false);
      }

      It's just the main idea, it's needed to fix some problems to compile.

       

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.