tor tor - 1 month ago 5
Java Question

Eclemma says 1 of 4 branches not covered, but which branch is it?

I feel like this is a dumb question, but is there a simple way to tell which branch I am missing? I.e. I have some code like this:

if (x || y) {
// Do stuff
}


In the coverage highlighting there is a yellow dot in Eclipse that says


1 of 4 branches missed


but I don't understand which case is not covered.

Answer

An open issue on the github repo for Eclemma's parent, jacoco, suggests that such a feature would actually be a bit difficult to include.

However, even without an Eclemma feature, if the goal is just to figure out the branches missed in a specific case, you could instrument your code to keep track. The simplest example is old fashioned print statements:

if (x || y) {
    System.out.println("BRANCH: " + x + ", " + y);
    // Do stuff
}

Then look at the output and see what branches you actually hit (e.g. java ... | grep "BRANCH:" | sort | uniq). (not terribly satisfying, I know.)

Comments