Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jacoco coverage ratio on 0.0

Tags:

java

jacoco

I have a problem with jacoco plugin in maven. Although i have some test lines in test files my coverage ratio is on 0.0. I dont know what can i do to make this work.

I've tried making changes in pom.xml from my friends pom, but this also doesn't work

here is the output from making maven.install:

--- jacoco-maven-plugin:0.8.3:check (default-check) @ Sudoku ---
Loading execution data file D:\xd\inf\4 semestr\Programowanie Komponentowe\prokom_2019_lch_sr_12_01\target\jacoco.exec
Analyzed bundle 'Sudoku' with 8 classes
Rule violated for bundle Sudoku: complexity covered ratio is 0.000000, but expected minimum is 0.600000

here is my pom.xml:


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.progkomp.Sudoku</groupId>
    <artifactId>Sudoku</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>sudoku</name>
    <url>http://maven.apache.org</url>


    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.0.0</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>checkstyle</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report</report>
                        </reports>
                    </reportSet>
                </reportSets>
                <version>0.8.3</version>
            </plugin>
        </plugins>
    </reporting>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <encoding>UTF-8</encoding>
                    <consoleOutput>true</consoleOutput>
                    <failsOnError>true</failsOnError>
                    <linkXRef>false</linkXRef>
                </configuration>
                <executions>
                    <execution>
                        <id>checkstyle</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.3</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule>
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit>
                                            <counter>COMPLEXITY</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.600000</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>


In test files i have about 100 lines with lots of asserts, so the problem is only with the plugin.

like image 972
Bonniu Avatar asked Oct 15 '25 03:10

Bonniu


2 Answers

In test files i have about 100 lines with lots of asserts, so the problem is only with the plugin.

The problem is clearly not "only with the plugin" and pom.xml is not enough to demonstrate your problem, because after addition of

src/main/java/Example.java

class Example {
}

and src/main/java/ExampleTest.java

public class ExampleTest {
  @org.junit.Test
  public void test() {
    new Example();
  }
}

and checkstyle.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
</module>

with exactly the same pom.xml execution of mvn clean install works perfectly fine:

...
[INFO] --- jacoco-maven-plugin:0.8.3:check (default-check) @ Sudoku ---
[INFO] Loading execution data file /private/tmp/j/target/jacoco.exec
[INFO] Analyzed bundle 'Sudoku' with 1 classes
[INFO] All coverage checks have been met.
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.071 s
[INFO] Finished at: 2019-04-25T15:45:10+02:00
[INFO] ------------------------------------------------------------------------

So please read https://stackoverflow.com/help/mcve and provide complete verifiable example with all parts needed to reproduce your problem.

like image 153
Godin Avatar answered Oct 18 '25 05:10

Godin


I was getting 0.0 coverage, because all my Test classes lack the Public scope, (they were private by default)

like image 42
Carlos Guizar Avatar answered Oct 18 '25 04:10

Carlos Guizar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!