Denis Defreyne

Test coverage is a lie

Test coverage is a metric, and any metric can be gamed. Test coverage can be gamed very easily: Ensure that for every piece of code, there is a test that runs it. However:

  • Don’t assert anything
  • Only execute one branch (unless branch coverage is enabled)
  • Catch and ignore all exceptions

Now you have 100% test coverage and a useless test suite.

See also

Note last edited April 2024.
Incoming links: