I am using a unit testing framework to test my libraries. I have quite a few assertions in the library to make sure that programmer errors are caught in debug builds. Now I want to make sure I am testing for all possible programmer errors.
E.g. in a Table class, I want to make sure that the rows and cols passes are not greater than the rows and cols the table has. Let’s assume I forget to test for cols. I would like to have my unit tests perform a test where the assertion should fire, and if not, fail the test. Is that possible?
The question then becomes are you planning on refactoring your code so that if this condition occurs you’ll throw an exception instead of relying on
<cassert>functionality to clue you into a problem? If so, you can just check that the exception was thrown. If not, then it’s going to be more difficult to test an assert statement from<cassert>. Unit test frameworks like CUTE have anASSERT_THROWSmacro just for exception testing. I’d check your framework.Also, it’s been the case with the shops where I’ve worked that they frown upon assert and prefer exceptions. Calling
abortdoesn’t help automated testing. Actually, it prohibits it. Just my two cents.