1001Ferramentas
🎯 Calculators

Test Coverage Target Calculator

How many lines are missing to hit your coverage target, how many of a PR's new lines need tests to keep the gate green, and how much untested code still fits.

For a pull request adding lines

How many lines are missing for the coverage gate

A team with a coverage gate in CI keeps running into the same three sums. The first is straightforward: I am at 75%, the target is 80%, how many lines do I need to cover? The second turns up mid pull request and is far less obvious. And the third almost nobody does — it is the one that prevents the surprise of breaking the gate without having touched a single test.

The sum that misleads is the pull request one. Covering 80% of the new lines does not keep the total at 80%: if the base sits above that, there is slack and you can cover less; if it sits below, covering even 100% of the new lines does not recover it. Enter how many lines the PR adds and the page says how many of them need tests — and warns when the gate is unreachable from the PR alone, which is the case where the problem is the base rather than what you are writing.

The third sum answers how much untested code still fits before coverage falls below the gate. With 900 of 1000 lines covered and a gate at 80%, another 125 lines fit with no tests at all — after that, any line brings it down. All the arithmetic runs on integers: 80% of 1000 is exactly 800, and an implementation that rounds up would ask for 801, sending you to cover one line more than necessary.

Frequently asked questions

Does this work for lines, branches or statements?
It works for any metric that is a ratio of covered to total — lines, statements, functions. Just use the numbers for the metric your gate checks. What does not work is mixing them: branch coverage tends to run well below line coverage in the same project.
Why does the PR requirement change with the base?
Because the gate looks at the total, not the PR. If you have 900 of 1000 and the gate is 80%, the total already carries 100 lines of slack; a 100-line PR can go in entirely untested and still pass. With the base at exactly 80% there is no slack at all and the PR has to hold the same ratio.
Does high coverage mean well-tested code?
No. It measures which lines ran during the tests, not whether anything was checked. A test that exercises a whole function and asserts nothing about the result gives 100% coverage and zero guarantee. The number is useful for finding what is not tested at all, which is where it genuinely helps.

Related Tools

The results provided by this tool are for general informational and educational purposes only and do not constitute professional, financial, medical, legal, tax or accounting advice. Always confirm important decisions with a qualified professional and official sources.