How should I use the results of Devel::Cover?

181 Views Asked by At

How should I use the results of Devel::Cover to make changes in the code? What do I do next with my code?

2

There are 2 best solutions below

0
On

Structural coverage is a metric of how thoroughly your code has been exercised. It's normally collected while running tests and thus provides an approximation of the completeness of your test suite.

Incomplete coverage means that you have functionality that isn't being exercised and thus can't be being tested. Normally you would add more tests to increase the coverage. Missed coverage can also be an indication of unnecessary functionality (which can be removed) or logical errors that prevent full exercise of the code. It's up to you to analyze your coverage reports and determine which course of action is appropriate.

Note that "covered" just means "executed." It is not the same as "tested" and definitely not the same as "correct." I recommend setting the flags to Devel::Cover (specifically ignore, inc, and select) so you collect coverage data only for the module actively under test. This reduces the risk of incidental coverage of untested code.

0
On

Use Devel::Cover to identify which parts of your code have not been exercised by your tests. If some parts of your code are not covered by your tests, you typically would add more tests to cover all of your code.

In some cases, Devel::Cover will identify parts of your code which can not be tested. If that is the case, you may decide to delete that part of your code.