Why do we use test coverage?

- Coverage provides a quantitative measurement of how well we have validated the code

 

Let's consider the following piece of code where test case is n=10

public boolean isTen(int n) {
    if (n == 10) {
    	return true;
    }
    return false;
}

Instruction Coverage

- how many instructions are covered

- a single line of code may be compiled to one or multiple bytecode instructions

Branch Coverage

- how many branches of the control structures (if, switch, etc) have been executed

- for this case, the false block is not covered, so the coverage is 1/2 = 50%

Line Coverage

- also known as statement coverage

- counts the number of lines (statements) executed

- If the input is n = 10, the fourth statement return false; is not ran, so the coverage is 3/4 = 75%

Method Coverage

- counts the number of methods executed

- for this case we only have one method, so the coverage is 1/1 = 100%

 

+ Recent posts