#When and Where to use Assertions.

1 messages · Page 1 of 1 (latest)

lime talon
#

Hey,
I just learnt that assertions in Godot are automatically removed from the final product. As I am more used to separate Test files I wonder what the best practices in Godot are.
Should I spread my assertions across my implementations to ensure I test everything on the spot or should I create separate test files and exclude them later on manually?
Both options seem to have their benefits like ...

  • ... having everything in one spot makes it easy to see check everything is tested properly and allows for catches in actual scenes ...
  • ... having everything in separate files keeps the code clean and easy to read ...
    ... as well as downsides ...
  • ... certain tests might require specific instantiation or rare edge cases that rarely come up during play.
  • ... separate tests might not catch cases I have not though of and will only encounter in an actual scene.
    As I don't have much experience with inline-asserts I would like to know if there is any established standard and what you personally prefer and why.
visual compass
#

Assertions are not really like assert statements in tests

#

Assertions are more like debug/throw statements; conditions which must hold for the following lines to be correct, but which for efficiency reasons are not worth running again every time the method is called

#

Consider a func documented to be valid only with sorted arrays

#

You might have an assert in the function that the array is, in fact, sorted

#

Which in dbg is nice! If it goes off, then you know you violated the constraint and have a bug in your code!

#

But in final release, running the expensive check on every call is wasted cycles (you caught and fixed the bug in qa, right?)