Unit tests

Unit tests have several uses, sorted by value:

  1. Frame the mindset when writing code: slower, more intentional.
  2. Identify over-engineered and over-complicated parts of the codebase.
  3. Ensure backwards-compatibility when refactoring or modifying existing code.
  4. Document the codebase through naming.
  5. Predict inputs/outputs of individual units of the codebase.

The test itself does not provide the value. The value comes from the mindset shift of the developer as they write the unit test. The code itself becomes shorter, simpler, and more sensible.

It’s preferrable to over-test rather than under-test when in doubt.