Our unit tests are written using the catch2 framework
In catch2 we prefer the
CHECK family of macros since they will continue the test in case of failure, while the
REQUIRE family would terminate.
In catch2, testing is particularly easy. For details, see the catch2 documentation above, but in short:
CHECK( expression ); where expression evaluates to a boolean, is just enough.
For all code we want to test all interfaces and basic functionality.
- see also the "coverage", which indicates the number of actual code lines that are tested by unit tests. We want this to converge to 100%.
Unit tests should be robust and run very fast.
- avoid extensive physics tests
- avoid statistical analysis with large number of events
- -> test expected behavior and formulas with minimal input
- if needed, complicated input-output data/objects must be replaced with simplified (empty) testing counterparts to basically only test the basic expectations, not complex behavior.
- unit tests must be as independent of each other as possible. Ideally they only depend on exactly the code they are testing.