Code Coverage definition
- It is a code quality metric.
- Code coverage is a measure used to describe the degree to which the source code of a program is executed or exercised when a particular test suite runs.
- Code coverage is a measure which describes the degree of which the source code of the program has been tested.
- It is one form of white box testing which finds the areas of the program which have been exercised by a set of test cases.
- Note that 100% coverage will not assert that the quality is perfect, but a low number will tell you that you have insufficient testing and the source code is error‐prone.
- In addition, for code coverage calculation all unit tests should be passed.
Code Coverage purpose
- Code Coverage is a measurement indicating the amount of product code that is exercised by tests.
Code Coverage drawbacks
- There is a tendency as a shortage to write tests in order to just increase the code coverage rather than discovering bugs.
- In addition, code coverage does not ensure that the most sensitive and important portions of the code are tested and does not necessarily provide functional coverage.
- Code coverage does not necessarily provide functional coverage.
- Code coverage could create incentives to write tests that simply increase coverage, rather than tests that find bus without increasing coverage.
- Code coverage does not ensure that the most important or highest risk areas of the code are being excised by tests.
- One of the drawbacks of code coverage could be that there might be incentives to write tests that simply increase code coverage, rather than tests that find bugs without increasing coverage.
- Code coverage does not represent or talk about the quality of the code which is being exercised.
- It just addresses “How much” code not “Which” code.
Code Coverage practice
- 90% of Unit test cases passed with 70% Code Coverage.
- This means 10 % of Unit Tests Cases failed, only 70 % of your code is checked and 30% of your code remains to be checked.
- / validated using unit or other kind of test.
Code coverage types
- Condition :
- Modified condition/decision coverage.
- Statement :
- Statement coverage and Block coverage.
- Path :
- Branch coverage.
- Function :
- Function coverage and Function call coverage.
More informations for the Scrum PSD certification here.