Jest come with functionality of generating report which help us in understanding test coverages. this coverage include statement , functional , branch coverages.
This is one example of test coverage report generated for test react app. This Report says it has 84% statement coverage , 100% branches and 100% functional and 84% lines coverage overall. than it display component wise report.
so what is mean of statement, Branches , functions , lines coverages etc.
- Function coverage Has each function (or subroutine) in the program been called?
- Statement coverage Has each statement in the program been executed?
- Branch coverage Has each branch (also called DD-path) of each control structure (such as in if and case statements) been executed? For example, given an if statement, have both the true and false branches been executed? Another way of saying this is, has every edge in the program been executed?
- Line coverage has each executable line in the source file been executed?
For each case, the percentage represents executed code vs not-executed code, which equals each fraction in percent format (e.g: 50% branches, 1/2).
Further we can click individual component or src file and see specific file report
For example index.js , no statement has covered.
In the file report:
'E'stands for 'else path not taken', which means that for the marked if/else statement, the 'if' path has been tested but not the 'else'.
'I'stands for 'if path not taken', which is the opposite case: the 'if' hasn't been tested.
xNin left column is the amount of times that line has been executed.
- Not executed lines, or pieces of code, will be highlighted in red.
It also provides some color codes -
Pink: statements not covered.
Orange: functions not covered.
Yellow: branches not covered.
So Test coverage help us to understand how effective our test cases are , Are we covering whole source or not.