Troubleshooting Code Coverage Issues

Qlty tells me there’s coverage changes on files I didn’t change. How is this possible?

While at first maybe not intuitive, it is possible, and in some cases very easy, for a change to one file to impact the code coverage metrics of another (untouched) file.

This can happen directly, and more obviously, by changing tests in such a way as to change the coverage of the files under tests, without a single change to the files under test.

However, it can also happen more indirectly. Consider a case where a function (under test) in File A makes a call to a function defined in File B. File B had 100% coverage … however, someone changes File A to remove the call to the function in File B: this reduces the coverage of File B indirectly.

There are also a number of other cases which can result in indirect coverage changes:

  • Incomplete or missing coverage reports
  • Dependency changes which change the execution path of tests
  • Tests that behave differently at different times of the day or in different environments