Menu

Exceptions - how to stop a test?

Ivo Dvorak
2005-02-11
2013-04-22
  • Ivo Dvorak

    Ivo Dvorak - 2005-02-11

    I have a test method SomeTest in a test class defined, using the CPPUNIT_TEST and other macros (the simplest way how to do it). I would like to have a possibility to stop the tests when something very bad happens. Generating exception will not help because CPPUNIT catches this exception and tests continue. How to tell CPPUNIT not to catch exceptions when needed? Or how else to do it?

    Thanks

    Ivo

     
    • Colin Wills

      Colin Wills - 2005-05-16

      My code is throwing an exception during a test and cppunit catches the exception, ends that test and says that the test was ok.  Is this expected behaviour?  If so I too would like to tell cppunit to not catch exceptions.

       
    • Colin Wills

      Colin Wills - 2005-05-16

      I found the cause of my problem: my exception was being caught somewhere unexpected in my own code.  There was no problem with CppUnit :-)

      Going back to the original post in this thread: I haven't tried this but if, like me, you are using TextTestRunner, you can pop the Protector object (via the TestResults object) which catches the exceptions thrown by the tests.  I think this would stop CppUnit catching exceptions.  Also you can create and push your own custom protector (start from CppUnit::DefaultProtector) and do whatever you want when exceptions are thrown.

       

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.