Test coverage metrics
Test coverage metrics are the measures that say how much of something has been tested, each as a share of a list: requirements with a test, statements or decisions the tests executed, risks that had a test run against them, browsers and devices tried. Every one counts what was reached, and none says whether the checks were good.
The longer version
Every coverage metric has the same form. A list of things that ought to be tested is drawn up, the ones a test has touched are counted, and the count is divided by the length of the list. The ISTQB glossary's definition of coverage says as much: "the degree to which specified coverage items are exercised by a test suite, expressed as a percentage". What separates one metric from another is the coverage item, the thing on the list. The ISTQB Foundation Level syllabus, version 4.0.1, gives requirements coverage and code coverage as its examples of coverage metrics, and elsewhere speaks of targets for the coverage of product risks, requirements or acceptance criteria. Sorting the metrics by what they count gives four families: requirements, code, risks and platforms.
Requirements coverage is the share of requirements, user stories or acceptance criteria that have at least one test, and it is read off a requirements traceability matrix. It shows which requirements nobody has tested, and it cannot show whether one linked test is enough for the requirement it is linked to. Code coverage is the share of the code that the tests executed, reported by a tool. Statement coverage counts executable statements, and decision coverage counts the true and false outcomes of each decision. The syllabus teaches branch coverage, a close relative of decision coverage, and states that it subsumes statement coverage. These figures show code that no test ran. They cannot show a requirement that was never implemented, since there is no code to count, or a test that ran a line and checked nothing. Risk coverage is the share of the items on a risk list that had a test run against them, and it names the exposure a release is carrying. Platform coverage is the share of the cells in a test matrix, such as pairs of browser and device, on which the tests were run.
One release can be put through all four. It has 24 requirements, and 18 of them have a test that was run, so requirements coverage is 18 ÷ 24, or 75 per cent. The tests executed 540 of the code's 720 statements, and 540 ÷ 720 is also 75 per cent. The risk list has 8 items and 5 had a test run, which is 5 ÷ 8, or 62.5 per cent. The test matrix has 12 cells and the suite ran on 9, another 75 per cent. Three of the four figures are equal and they describe different things, so they cannot be added or averaged into one number. The use of each lies in its remainder: 6 requirements, 180 statements, 3 risks and 3 pairs of browser and device that nothing has touched. If one of the three risks is the payment step, that line matters more than any of the percentages. None of these figures comes with a pass mark. The syllabus lists an achieved level of coverage among typical exit criteria and leaves the level to be set for each test effort, and a figure made into a target can be raised by tests that execute code without checking it.
Coverage tools report more code items than statements and decisions. Function coverage counts the functions called at least once. Condition coverage counts the single true or false conditions inside a decision, such as each half of a check that the user is signed in and the basket is not empty, and asks for each one to be evaluated both ways. The specification-based techniques have coverage items of their own. The syllabus measures equivalence partitioning as the partitions exercised by at least one test, divided by the partitions identified, and boundary value analysis the same way with boundary values. The words are used loosely across the industry: several guides define test coverage as the share of features tested and treat code coverage as one kind of it, while others use the two terms as synonyms. Naming the coverage item next to every figure, as in 75 per cent of requirements or 75 per cent of statements, removes the ambiguity, because the sum is the same in every case: items covered ÷ items in total × 100.
Common questions
What are test coverage metrics?
Test coverage metrics are measures of how much of a defined list the tests have exercised, expressed as a share of that list. The list may hold requirements, statements or decisions in the code, risks, or combinations of browser and device. The ISTQB glossary defines coverage as the degree to which specified coverage items are exercised by a test suite, expressed as a percentage.
How do you calculate test coverage?
Choose the coverage item, count how many of those items the tests exercised, divide by the total and multiply by 100. A suite that exercised 6 of the 8 equivalence partitions identified for a field has partition coverage of 6 ÷ 8 × 100, or 75 per cent. The same sum applies to requirements, statements, branches, risks or browsers, so the report has to name which one it counted.
What is the difference between test coverage and code coverage?
Code coverage is one kind of test coverage: the share of statements, branches, conditions or functions that the tests executed, measured by a tool. Test coverage is the wider idea and can count any list, such as requirements, features, risks or supported browsers. A product can show high code coverage and still have a requirement with no test, which only the wider measures reveal.
What other test metrics are there besides coverage?
The ISTQB Foundation Level syllabus groups test metrics into seven kinds: project progress, test progress, product quality, defect, risk, coverage and cost metrics. Test progress covers cases run, passed and failed, defect metrics cover numbers found and fixed and defect density, and risk metrics cover the residual risk level. Coverage metrics are the kind that say what has not been tested yet.
How is requirements coverage calculated?
Divide the number of requirements that have at least one test by the total number of requirements. With 30 requirements and tests linked to 27, coverage is 27 ÷ 30, or 90 per cent, and the three unlinked requirements are the finding. The count can mean requirements with a test written, a test run or a test passed, so a report has to say which.
What is the difference between requirements coverage and code coverage?
Requirements coverage counts requirements that have a test, and it comes from the links in a traceability matrix. Code coverage counts the statements or branches the tests executed, and it comes from a tool that watches the code run. Requirements coverage misses code nobody specified, and code coverage misses requirements nobody implemented, which is why the two are reported side by side.
Which test coverage metric should a team report?
The metric to report is the one that matches the decision being made. A release decision is served by requirements coverage and risk coverage, with the untested items named. Developers deciding where to add tests are served by statement and decision coverage for the code they changed. Platform coverage answers a question about where the product was tried, and none of the four replaces another.
Does a high coverage figure mean the software is well tested?
A high coverage figure means that most of the items on a list were reached by some test. Whether those tests would notice a wrong result is outside what the figure measures: a test that executes a line and asserts nothing is counted like any other. Coverage is most reliable read from the low end, where an untested requirement or an unexecuted branch is a plain fact.
Bug reports that arrive ready to triage.
Collect replay, console, network and browser context with the Free plan.