0

I've had a look at some of the qtest source code and documentation and can't figure it out.

Would like to run tests and have test cases fail if an exception is thrown, and then continue on to the next test.

Is there a way short of recompiling qt with various macros defined/undefined? or adding try/catch blocks to every test?

or some way to get something like this to work?

QT_BEGIN_NAMESPACE
#define QCOMPARE_NOEXCEP( actual, expected )\
try{\                                                 
        QCOMPARE( actual, expected );\                 
} catch( ... ) {\                                   
    QFAIL( "Exception thrown" );\                  
    return;\                                       
}\
QT_END_NAMESPACE
codeMetis
  • 420
  • 4
  • 16
  • 1
    Normally when you write a test you know beforehand whether it will or should throw exceptions or not. If you don't - your application is unpredictable and you have to fix it first. Anyways, if you don't know which exceptions to handle, you need to add try/catch blocks around your code and report test failure on exception. If exception is expected use `QVERIFY_EXCEPTION_THROWN` macro. – vahancho Feb 05 '18 at 08:14
  • I guess my thinking with test driven development, you shouldn't have to know if the implementation will throw an exception. you shouldn't have to know about the implementation period. To me that's just bad code, failing a test and I've used other tools that handle exceptions in tests as test failures in c#. But this is testing more than one system, rather than unit testing - maybe i'm wrong for doing so, but this is the work that has been requested. I ended up writing two macros so I could at least reduce the million try catch all blocks to a few chars before/after the test code – codeMetis Feb 06 '18 at 01:30
  • exceptions that your code throws is different though, and if I was doing that then yes of course I'd use the `QVERIFY_EXCEPTION_THROWN`. I'm just trying to handle human stupidity and exceptions thrown from std libs and such. – codeMetis Feb 06 '18 at 01:32

0 Answers0