EMZETT.
Login

Code coverage

In short: Code coverage measures what share of the program code is executed by tests, for example “80 % of lines”.

In more detail: It shows untested places but says nothing about the quality of the tests: a line can be executed without its result being checked. High coverage is necessary but not sufficient.

In Depth

  • Types: line coverage, branch coverage (each if both ways), path coverage.
  • Sensible goals: 70 to 90 % for logic. 100 % at any price leads to worthless tests.
  • Mutation testing: deliberately changes the code and checks whether the tests notice. That measures effectiveness better.
  • More important than the number: Test critical paths (payment, authorisation, calculations) well.
  • Tools: c8 and Istanbul (JS), JaCoCo (Java), coverage.py (Python).

See also: Mocking and test doubles, Test-driven development (TDD)