Measuring code coverage
Measuring code coverage is essentially the evaluation of how effective our unit or integration tests are and whether they test statements, conditions, and functions for all possible results and arguments. When calculating code coverage, the coverage engine launches test suites with special instrumented code at runtime so as to measure which statements of the code were reached or not.
Some of the basic coverage criteria are as follows:
Method coverage: Call to each method of a class
Condition coverage: Evaluation of Boolean expressions to true or false
Decision coverage: Reach all different branches within a control flow; for example, all cases in a
switch
statement are covered, code tests bothif
andelse
execution pathsStatement coverage: All statements within a method or block were reached by the test suite