Source: TesterHome Community
Technical Manager at a domestic joint-stock commercial bank. With more than 16 years of experience in software testing, development and project management, the author has in-depth insights into industrial test quality management and automated testing systems.
Jin Yong’s classic wuxia novels feature six major orthodox sects in the martial arts world. Similarly, the software testing industry has no unified standard for test coverage measurement. Instead, multiple mainstream methodologies have been formed in actual corporate practice.
As a core metric, test coverage is widely used to evaluate the adequacy and completeness of software system testing. After years of industry research and communication with front-line testing practitioners, I have summarized six mainstream schools of thought for test coverage calculation.
This article systematically introduces the core logic, calculation methods, applicable scenarios and inherent limitations of each methodology.
This methodology focuses on simplifying the testing statistics process with minimal workload input. Its core feature is that all coverage data relies entirely on subjective manual judgment by testers.
Test Coverage = Manually Executed Test Cases / Total Test Cases
Both the numerator and denominator are defined artificially without objective quantitative standards.
For example, testers subjectively confirm that all written test cases have been executed, and directly mark the test coverage as 100%. The total number of test cases is also fixed based on the current team’s output, without considering potential missing scenarios.
Although this method is extremely convenient and low-cost, it lacks objectivity and accuracy. Nevertheless, it is still adopted by many small and medium-sized teams in the industry.
Popular among traditional software enterprises, this school replaces subjective manual judgment with objective automated data statistics. It formulates clear quantitative formulas, with three mainstream implementation methods in actual work.
Calculation Formula: Covered Interfaces / Total System Interfaces
If a system has 10 built-in interfaces and automated test scripts cover 8 of them, the API test coverage reaches 80%.
Calculation Formula: Automated Script Cases / Total Test Cases
For a system with 100 standardized test cases, if 60 cases are converted and executed through automated scripts, the automated test coverage is 60%.
Calculation Formula: Covered Functional Checkpoints / Total Functional Checkpoints
100 test cases of a system correspond to 400 core functional checkpoints. If automated tests verify 200 checkpoints effectively, the functional coverage is 50%.
The biggest advantage of the data-driven methodology is standardized and credible data. It completely avoids the "guesswork" problem of manual evaluation and is one of the most practical coverage measurement methods in enterprise-level testing.
This is a highly traditional and academic methodology derived from formal patented technical solutions. Its complete set of logical processes is extremely rigorous but overly complicated for daily testing work.
The core standardized process of the patented coverage calculation method is as follows:
The supporting system covers multiple professional modules including requirement acquisition, case splitting, coverage statistics and data calculation. Due to its cumbersome logic, high threshold and poor practicability, this methodology is rarely used in daily testing business and is more inclined to theoretical academic research.
All test cases are designed based on business requirements rather than code implementation logic. This school takes requirement coverage as the core standard to measure testing completeness, focusing on verifying whether all business requirements are fully covered by tests.
Test Coverage = Tested User Stories/Tasks / Total User Stories/Tasks
For coarse-grained original requirements, testers will disassemble them into refined user stories, and further split stories into executable business tasks. Coverage statistics are carried out based on standardized stories or tasks.
The biggest limitation of this method is dependency on manual marking. There is no mature tool in the industry that can automatically identify requirement coverage status, resulting in certain subjective errors in the final data.
The granularity of requirement disassembly has no fixed standard and needs to be adapted according to the business characteristics of different enterprises. The core logic can be learned from the classic fable Cook Ding Carving Oxen from Zhuangzi.
A skilled tester is just like an experienced chef. Instead of mechanically splitting requirements, they can sort out the internal logical structure of complex businesses, split requirements along the natural business boundaries, and form standardized, testable user stories and tasks.
The ultimate goal of requirement coverage testing is to ensure that every business requirement is effectively verified, so as to fundamentally guarantee product quality.
This is a niche and unconventional coverage measurement methodology, which is mainly used for risk regression control of historical defects and adopted by a small number of large-scale technology companies.
During the 3-month development and launch cycle of System A, the testing team found and repaired 70 valid defects. To avoid repeated regression bugs in subsequent iterations, the team converted all repaired defects into automated regression test cases for daily cyclic execution.
Typical Defect Scenario: The full-screen pop-up function of Page A Button B failed. After the developer fixed the bug, testers wrote a dedicated automated script to continuously verify the pop-up full-screen effect, completely preventing the recurrence of historical bugs.
Test Coverage = Automated Defect Regression Cases / Total Repaired Historical Defects
This reverse measurement method focuses on defect closed-loop management and regression risk prevention. Although it cannot cover all business scenarios, it has outstanding effects in stabilizing system iteration quality.
As the most widely recognized and authoritative mainstream methodology in the industry, code coverage measures testing sufficiency based on the actual execution of underlying code, mainly including line coverage and branch coverage.
Calculation Formula: Executed Code Lines / Total Executable Code Lines
It refers to the proportion of all code lines that are triggered and executed during test operation.
Calculation Formula: Executed Logical Branches / Total Conditional Branches
It counts the coverage rate of all conditional judgment branches in the code, which can effectively verify the integrity of logical branches.
In addition, common code coverage dimensions include class coverage, method coverage and file coverage, all of which evaluate testing adequacy from different code granularities.
Code coverage data is automatically collected and generated by professional third-party tools, with mature solutions for different programming languages:
My team adopts a hybrid model combining code coverage and data-driven coverage. Based on the JaCoCo tool, we eliminate invalid template code and only count core business code coverage to ensure data authenticity and reference value.
Build a standardized coverage statistics environment based on project technology stack to ensure independent and undisturbed data collection.
Initially, the coverage rate is 0%. After executing all automated scripts, the tool generates visual coverage reports through color marking:
Note: Do not manually operate the test environment during statistics to avoid distorting coverage data.
In SpringBoot projects, exclude non-business template directories such as bean, model, entity, util, mapper and config. Only retain core business directories (controller, service) for coverage statistics.
Filtering invalid code can effectively avoid inflated false-high coverage data and truly reflect the testing adequacy of core business logic.
It is crucial to note that 100% code coverage does not mean zero system bugs.
Code coverage only verifies that the code is executed at least once, but cannot cover all parameter combinations, execution sequences and extreme boundary scenarios. A single covered code line may lack verification of abnormal logic and error scenarios.
The core value of code coverage is not to pursue high numerical indicators, but to identify uncovered red code segments, discover test case omissions and testing blind spots, and guide testers to supplement test scenarios to improve overall testing quality.
Test coverage is an indispensable quantitative indicator for testing quality management. Testing work without coverage data is equivalent to "working in the dark" with no clear quality vision.
Teams should actively collect and continuously optimize coverage data. By monitoring coverage changes for a long time, we can effectively make up for testing deficiencies, standardize testing processes and steadily improve software testing maturity.