Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set jacoco code coverage levels to module in gradle

I'm using gradle 4.3.1 with the jacoco plugin and I am able to ensure a certain level of code coverage in a a multi module project. This works great when I set the element to CLASS or PACAKAGE, but I'm stumped on how to get it work for the module.

Looking here I think what I want is BUNDLE or GROUP, but then jacoco does not break when I go under the coverage amount.

Here is an example of what I have that does work for package level coverage enforcement :

jacocoTestCoverageVerification {
    violationRules {
        rule {
            // should be element = 'BUNDLE' or 'GROUP'? 
            element = 'PACKAGE'

            limit {
                minimum = 0.9
            }
            includes = ['com.mypackage.*']
        }
    }
}

When I change the element value to BUNDLE the build does not fail regardless of coverage. Again I'd like to be able to control the expectation at the module level.

Here is my gradle version information:

------------------------------------------------------------
Gradle 4.3.1
------------------------------------------------------------

Build time:   2017-11-08 08:59:45 UTC
Revision:     e4f4804807ef7c2829da51877861ff06e07e006d

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_40 (Oracle Corporation 25.40-b25)
OS:           Windows 8.1 6.3 amd64

I'm guessing I'm missing something pretty simple, since I don't think I'm the first to try to do this. Any help would be appreciated!

like image 435
Tristan Avatar asked Dec 22 '17 14:12

Tristan


People also ask

How do I get gradle code coverage?

Getting Started To get started, apply the JaCoCo plugin to the project you want to calculate code coverage for. If the Java plugin is also applied to your project, a new task named jacocoTestReport is created. By default, a HTML report is generated at $buildDir/reports/jacoco/test .

How do I use JaCoCo code coverage?

Step 4: To get you code coverage report navigate to the target > site > jacoco > index. html > right-click > Open In > Browser > And your preferred browser. So basically index. html is your code coverage report file.


1 Answers

I am not very sure of this, but could you try adding counter='LINE' inside limit.

rule {
       element = 'GROUP'

       limit {
           minimum = 0.9
           counter = 'LINE'
       }
...

Apart from that also try to add jacocoTestReport for generating test report to verify your result for internal testing purpose only.

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination file("${buildDir}/jacocoHtml")
    }
}

Source: https://docs.gradle.org/current/userguide/jacoco_plugin.html#sec:jacoco_report_configuration

like image 200
Akash Chandwani Avatar answered Oct 11 '22 23:10

Akash Chandwani