The code coverage is the measurement of how much the product code has been exercised with all unit/functional/system tests.
A typical code coverage tool would produce metrics like how many or % of Java classes covered, methods covered, loops and instructions covered.
The significance of code coverage is to help in identifying the gaps in testing and also to assess the test coverage. Also, 100% code coverage should not be viewed as a high quality of the product. Instead, the results can trigger some more testing or optimization of the code.
Many times, code coverage is done after fully tested the product to see if any dead code or to find the missed testing coverage. Most of the times, the code coverage can be taken at the class level but at least method level is important. Usually, the QE team will report code coverage reports on regular basis.
The QA engineer should co-ordinate with all relevant test teams in carrying out such effort. The major tasks include the understanding of the tool and automation of the enabling the tool with the installed product, gathering the results, merging of results from different runs and publishing of the collective report. The report will be distributed to the stakeholders by a Java package name or by a module. Each module-level QE engineer can see if the results are appropriately covered or not and add the tests if required to cover all the classes and methods in that module. The feedback should be taken into the developer team to add unit tests or remove the dead or unused code for the product. Usually above 40-50% code coverage is considered as high coverage.
Why not 100% coverage target? It is all about human resources invested for testing of the product, and thereby 100% means that enormous test engineering resources requirement and practically is not feasible. Achieving higher code coverage can be aimed for any product as part of the quality testing of the product.
Some of the free and open source code coverage tools are
- JaCoCo (nowadays more popular and originally developed from Emma)