Characteristics of tests

Characteristics of a good unit test

  • Fast: It isn't uncommon for mature projects to have thousands of unit tests. Unit tests should take little time to run. Milliseconds.

  • Isolated: Unit tests are standalone, can be run in isolation, and have no dependencies on any outside factors such as a file system or database.

  • Repeatable: Running a unit test should be consistent with its results, that is, it always returns the same result if you don't change anything in between runs.

  • Self-Checking: The test should be able to automatically detect if it passed or failed without any human interaction.

  • Timely: Unit tests should be written close to when the code is written, ideally before or during the development process (TDD approach).

Last updated