nbaztec / coveralls-jacoco-gradle-plugin

Coveralls JaCoCo Gradle plugin
MIT License
23 stars 15 forks source link

Branch coverage not sent #67

Closed Khaseyama closed 6 months ago

Khaseyama commented 11 months ago

I was able to display Line coverage using coveralls-jacoco-gradle-plugin and circleCI. But I don't see branch coverage. Branch coverage was visible when I don't use coveralls-jacoco-gradle-plugin. Can coveralls-jacoco-gradle-plugin be made to show branch coverage?

https://docs.coveralls.io/api-jobs-endpoint#:~:text=JSON%20OBJECT%3A%20SOURCE%20FILE

nbaztec commented 11 months ago

Hi, it seems that while JaCoCo supports branch coverage, it's not exactly translatable to what coveralls expects. I might take a look at it if I get some time, but it may not be trivial to implement an/or give the desired information on branch hits/misses.

snackattas commented 7 months ago

+1

afinetooth commented 7 months ago

Hi, @nbaztec, @snackattas.

From the coveralls.io side, let us know if we can help with the implementation.

In case it helps as a reference, I've attached an example of a Coveralls JSON-format Coverage Upload (the JSON file any Coveralls integration ultimately POSTs to https://coveralls.io/apio/v1/jobs):

Coveralls JSON-format Coverage Upload Example (4 files only) - 2024-03-18T100620.241.json

In this example I've removed all but the first four (4) files in the source_files collection. The first two files have branch coverage stats; the second two do not (thus the empty branches collection on those).

About the branch coverage format:

In a Coveralls JSON-format coverage report, branch coverage is represented under the branches key within each entry in source_files. This key contains an array of numbers that represent the coverage data for branches in the source code. Each group of four numbers in this array represents a single branch point in the code, structured as follows:

  1. Line number: The line number in the source code where the branch point is located.
  2. Block number: A unique identifier for a section of code within a method or function.
  3. Branch number: A unique identifier for the branch within the block.
  4. Hits: The number of times that particular branch has been executed during testing.

For example, consider the first entry under the branches key for lib/enterprise.rb:

This indicates that at line 43 in the lib/enterprise.rb file, there are several branches (identified as branches 1, 2, 3, 4 in block 0), and none of these branches were executed during testing (as indicated by the 0 hits).

Let me know if you have any questions.

nbaztec commented 7 months ago

Thanks @afinetooth this is certainly helpful.

Since jacoco generates a report per line, where nr: line number, mb: missed branches, cb: covered branches, in the example below, the line 7 has 1 missed branch and 2 covered branches:

<sourcefile name="Foo.kt">
    <line nr="7" ... mb="1" cb="2"/>
</sourcefile>

I presume I can expand the branch entries requested by coveralls, as such:

{
    ...
    "branches": [
        7,0,1,0,    // mb1
        7,0,2,1,    // cb1
        7,0,3,1,    // cb2
    ],
    ...
}

and that will generate the correct/equivalent coverage.

nbaztec commented 6 months ago

@Khaseyama I wanted to verify branch coverage before the 1.2.20 release once but didn't get around it. Could you please verify if it works for you now?

Khaseyama commented 6 months ago

@nbaztec

@Khaseyama I wanted to verify branch coverage before the 1.2.20 release once but didn't get around it. Could you please verify if it works for you now?

thank you, I'll check. It may take a while.

Khaseyama commented 6 months ago

@nbaztec I have confirmed that branch coverage is displayed in Coveralls in ver1.2.20. Thank you!