Code coverage is a software testing metric also termed as Code Coverage Testing which helps in determining how much code of the source is tested which helps in accessing the quality of the test suite and analyzing how comprehensively a software is verified. Actually in simple code coverage refers to the degree to which the source code of the software code has been tested. This Code Coverage is considered as one of the forms of white box testing.
Code Coverage metric helps in determining the performance and quality aspects of any software. The formula to calculate code coverage is
Code Coverage = (Number of lines of code executed)/(Total Number of lines of code in a system component) * 100
Code Coverage Criteria
To perform code coverage analysis various criteria are taken into consideration. These are the major methods/criteria which are considered.
1. Statement Coverage/Block coverage:
The number of statements that have been successfully executed in the program source code.
Statement Coverage = (Number of statements executed)/(Total Number of statements)*100.
2. Decision Coverage/Branch Coverage:
The number of decision control structures that have been successfully executed in the program source code.
Decision Coverage = (Number of decision/branch outcomes exercised)/(Total number of decision outcomes in the source code)*100.
3. Function coverage:
The number of functions that are called and executed at least once in the source code.
Function Coverage = (Number of functions called)/(Total number of function)*100.
4. Condition Coverage/Expression Coverage:
The number of Boolean condition/expression statements executed in the conditional statement.
Condition Coverage =(Number of executed operands)/(Total Number of Operands)*100.
Tools For Code Coverage
Below are a few important code coverage tools
- Cobertura
- Clover
- Gretel
- Kalistick
- JaCoCo
- JTest
- OpenCover
- Emma
- GCT