I’m not used yet to write unit tests and I want to do this on a full framework of little tools (making it more secure to use). That way I’ll certainly learn more about unit tests than what I learnt until now.
However I’m really used to add assertions systematically everywhere I see there is a context to be sure about (that are removed in the final release). Mostly as preconditions in functions implementations and each time I retrieve informations that have to be correct (like C/C++ pointers validity for a famous example).
Now I’m asking : are assertions redundant when you have unit tests? Because it looks redundant as you’re testing the behaviour of a bit of code; but in the same time it’s not the same execution context.
Should I do both?
Assertions that check preconditions can help detect and locate integration bugs. That is, whereas unit tests demonstrate that a method operates correctly when it is used (called) correctly, assertions that check preconditions can detect incorrect uses (calls) to the method. Using assertions causes faulty code to fail fast, which assists debugging.