I have been using CPPUnit as a unit testing framework and am now trying to use it in an automated build and package system. However a problem holding me back is that if a crash occurs during the running of the unit tests, e.g. a null pointer dereferencing, it halts the remainder of the automation.
Is there any way for CPPUnit to recover from the exception, record the test failure and then exist gracefully rather than terminating the unit test process? Even an approach specific to null pointer dereferencing would be useful as that makes up about 90% of the issues I have had.
To be technology-specific, I am using makefiles on a Windows system.
You’re automating the execution of your cppunit-based unit-tests during your build process, right ?
If you were trying to use CppUnit to execute the build process, I would be tempted to say don’t do that !
Could you tell us what is stopping the build process when the unit tests crash ? And what are your unit tests started by, a Makefile, a script of your own, or a continuous integration framework ?
To try to answer your question, CppUnit cannot recover from violation or segmentation errors. On Unix-like systems you should be able to catch the SIGSEGV and to continue, but in which state ?
If your crashes occur in your unit test and not in your product, then I’d recommend you to rely on assertion guards to prevent dereferencing NULL pointers: