terma / github-pr-coverage-status

Nice test coverage icon for your pull requests just from Jenkins
Apache License 2.0
4 stars 6 forks source link

[Cobertura] Wrong percentage being published #25

Open gustahrodrigues opened 7 years ago

gustahrodrigues commented 7 years ago

Hi guys,

I think that we're publishing the wrong percentage on Github. I think it should be about 62% at least.

Information: Coverage tool: Python coverage XML commands:

[root@aeinav-nb vagrant]# coverage erase
[root@aeinav-nb vagrant]# <run_tests>
[root@aeinav-nb vagrant]# coverage xml

HTML commands:

[root@aeinav-nb vagrant]# coverage erase
[root@aeinav-nb vagrant]# <run_tests>
[root@aeinav-nb vagrant]# coverage html

Github:

image

HTML result:

image

Jenkins job:

<?xml version="1.0" ?>
<!DOCTYPE coverage
  SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0.4457" line-rate="0.6628" timestamp="1494454522819" version="3.6b3">
    <!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage/3.6b3 -->
    <packages>
        <package branch-rate="0.4457" complexity="0" line-rate="0.6628" name="">
                <classes>......</classes>
        </package>
    </packages>
</coverage>
19:37:17 Coverage 55% changed 0.0% vs master 55%

Master record:

<?xml version="1.0" ?>
<!DOCTYPE coverage
  SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0.4451" line-rate="0.6619" timestamp="1494486306467" version="3.6b3">
<sources> <source>/jenkins/workspace/RHEL/BDD-REGRESSION-RHEL</source> </sources>
    <!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage/3.6b3 -->
    <packages>
        <package branch-rate="0.4451" complexity="0" line-rate="0.6619" name="">
            <classes>
                            .....
            </classes>
        </package>
    </packages>
</coverage>
08:16:54 Master coverage +55%
BenjaminGill-Metaswitch commented 7 years ago

From src/main/java/com/github/terma/jenkins/githubprcoveragestatus/CoberturaParser.java:

            if (lineRate > 0 && branchRate == 0) {
              return lineRate;
            } else if (lineRate == 0 && branchRate > 0) {
              return branchRate;
            } else {
              return lineRate / 2 + branchRate / 2;
            }

Thus, you're getting the average of 0.4451 and 0.6619, which is ~ 55%.

It might help if this were documented, however.