Skip to content

jacocoTestCoverageVerification : How gitlab counts test coverage – Spring Boot?

I have a project where Sprig Boot, JUnit and Gradle are being used. In the Gradle dependency I have found the following lines :

jacocoTestCoverageVerification {
    violationRules {
        rule {
            limit {
                minimum = Float.parseFloat(System.getenv().getOrDefault("CI_TEST_COVERAGE_REQUIRED", "0.7"))

As par me these lines indicating that in the Gitlab the test coverage must the 70% at least.

When I have the run tests with coverage in IntelliJ IDE, I have got 3 measurements, shown in the image.

enter image description here

So, we have got 3 values, which are different and indicating several types.

So my concern is that how the one single value 70% will be calculated from these 3 values?

Is there any way or command to get this single 70% or .7 value?



By going through the documentation from JacocoCoverageVerification to JacocoViolationRule and finally JacocoLimit#getCounter

The counter that applies to the limit as defined by org.jacoco.core.analysis.ICoverageNode.CounterEntity. Valid values are INSTRUCTION, LINE, BRANCH, COMPLEXITY, METHOD and CLASS. Defaults to INSTRUCTION.

So the default is INSTRUCTION, of course you can specify the value of counter as CLASS, METHOD or LINE.

In case you want to know the difference between LINE and INSTRUCTION, please take a look on Lines of Code VS Instructions while measuring code quality.

5 People found this is helpful