I am trying to understand what type of test coverage metric Eclipse uses.
I wrote two simple functions as follows:
public class Hello {
public void f(int a, int b) {
int sum = a + b;
if (sum > 0)
print("blue");
else if (sum < 0)
print("red");
print("done");
}
void print(String s) {
System.out.println(s);
}
public void g(int x, int y) {
if (x == 0 || y > 0) {
print("red");
} else {
print("blue");
}
}
}
Then I called the functions from the unit tests like this:
import org.junit.jupiter.api.Test;
class TestHello {
@Test
void test_f() {
new Hello().f(2, 4);
new Hello().f(-1, -2);
new Hello().f(-1, 1);
}
@Test
void test_g() {
new Hello().g(0, 5);
new Hello().g(5, 0);
new Hello().g(0, 0);
//new Hello().g(5, 5);
}
}
As a result, for the function g, Eclipse says that "1 of 4 branches missed" and marks the line 18 yellow.
On the other hand, the coverage window shows that the function g is 100% covered while the green bar on the first column is not as long as the function f one where I thought these bars showed how much close you are to 100%.
So I am trying to make sense out of all of this. Does Eclipse use:
- branch coverage
- condition coverage
- branch and condition coverage
- modified condition / decision coverage (mc/dc)
- multiple condition coverage (mcc)
- something else?
According to %100 coverage shown on the coverage window, it may be using branch and condition coverage. However, the yellow marked line may tell me that it uses something stronger like mc/dc or mcc. Then, there is progress-bar looking-like green bar which I am not sure what is trying to tell me?
I appreciate if someone more knowledgeable than me can make sense out of all these observations and can explain what metric Eclipse is using and what the progress bar means compared to the percentage?