Get branch probes

15 views
Skip to first unread message

amohi...@gmail.com

unread,
Dec 4, 2017, 2:45:54 PM12/4/17
to JaCoCo and EclEmma Users
Hello! I'm trying to get some information about a coverage run.
I have statements probes array (ExecutionData), which I collect using an ExecutionDataVisitor, collecting statements probes array for each test run (using a custom JUnit listener).

Now I need to figure out which method/branch from each executed class have been executed.

I managed to retrieve numbers about covered methods/branches/statements by analyzing the ExecutionData using a CoverageBuilder. I found also that I can check the name of each method executed and with this I can generate my own list of which of all methods have been executed. Now I need to do the same with branches, but I didn't figure any way to do this. The ideal would be an array containing all possible executable branches and those that were executed, marked with a flag (same mechanism as ExecutionData).

Anyone can provide me some light?
Thanks in advance!

amohi...@gmail.com

unread,
Dec 4, 2017, 3:42:12 PM12/4/17
to JaCoCo and EclEmma Users
I found a way to do it.
I visit every line of a ClassCoverage checking the TotalCount of the BranchCounter, if it is greater than 0, then there is a branch in that line. To check if it is visited, I check if the CoveredCount is different than 0.

Here is the snippet for the code (keep in mind that it is an experimental code):

for (IClassCoverage classCoverage : coverageBuilder.getClasses())
{
boolean[] branchProbes = new boolean[classCoverage.getBranchCounter().getTotalCount()];
int currentBranchIndex = 0;
if (branchProbes.length != 0)
{
for (int x = 0; x < classCoverage.getLastLine(); x++)
{
ILine line = classCoverage.getLine(x);
if (line.getBranchCounter().getTotalCount() != 0)
{
branchProbes[currentBranchIndex++] = line.getBranchCounter().getCoveredCount() != 0;
}
}
}

I'm sharing in case someone needs it in the future.

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages