maven jacoco plugin does not generate coverage report

makingitwork

I am using sonarqube as the output for the test results, while maven and jacoco for testing the test cases.

Sonarqube version is 5.4 Maven version is 3.3.9 Jacoco version 0.7

This is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.sonarqube</groupId>
  <artifactId>example-ut-maven-jacoco</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>Java :: UT Coverage with JaCoCo :: Maven</name>

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

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <!-- Minimal supported version is 4.7 -->
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.6.201602180812</version>
    </dependency>

  </dependencies>

  <build>
    <plugins>
         <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.5.201505241946</version>
    <executions>
        <!--
            Prepares the property pointing to the JaCoCo runtime agent which
            is passed as VM argument when Maven the Surefire plugin is executed.
        -->
        <execution>
            <id>pre-unit-test</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <!-- Sets the path to the file which contains the execution data. -->
                <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                <!--
                    Sets the name of the property containing the settings
                    for JaCoCo runtime agent.
                -->
                <propertyName>surefireArgLine</propertyName>
            </configuration>
        </execution>
        <!--
            Ensures that the code coverage report for unit tests is created after
            unit tests have been run.
        -->
        <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <!-- Sets the path to the file which contains the execution data. -->
                <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                <!-- Sets the output directory for the code coverage report. -->
                <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
            </configuration>
        </execution>
    </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.15</version>
        <configuration>
            <!-- Sets the VM argument line used when unit tests are run. -->
            <argLine>${surefireArgLine}</argLine>
            <!-- Skips unit tests if the value of skip.unit.tests property is true -->
            <skipTests>${skip.unit.tests}</skipTests> 
        </configuration>
    </plugin>
    </plugins>
  </build>



</project>

I am also following this link here but for the files I am using the ones here enter link description here.

This how I build the project for testing

mvn clean test
mvn clean verify
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install
mvn sonar:sonar

The buiild returns successful but there are no code coverage generated I also checked this by going to sonarqube localhost:9000/ it displays 0.00% code coverage but the unit test are all presented as successful "it is successful".

Any idea as to what might cause this problem? Also I am still new to all of this.

wemu

The setup looks ok from my point of view.

You have changed the default name of the report file. Therefore I would guess you need to tell that to the sonar analyser as well.

The jacoco default for unit tests is: ${project.build.directory}/jacoco.exec Thats also the name sonar will try to pick up.

You can simply set a property to indicate the location for the sonar analyzer:

<properties
    <sonar.jacoco.reportPath>${project.build.directory}/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPath>
    ...

Please verify if your jacco file exists and is non empty - if so sonar will sooner or later pick it up once the location is correctly configured.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Generate Code Coverage with JaCoCo and spring-boot-maven-plugin

From Dev

maven jacoco: not generating code coverage report

From Dev

build.gradle with Jacoco plugin doesn't generate coverage report for integration tests

From Dev

maven-surefire-plugin, jacoco-maven-plugin show no coverage

From Dev

Jacoco generate coverage report for only a single test class

From Dev

Exclude folder in jacoco coverage report

From Dev

Jacoco Coverage and Report Task with Ant

From Dev

JaCoCo Debug Coverage Test Report

From Dev

How to generate xml report with scoverage maven plugin?

From Dev

Generate coverage report with stack

From Dev

Generate coverage report with stack

From Dev

How to report Jacoco Groovy code coverage to Sonar using new Gradle SonarQube plugin?

From Dev

How do I get a jacoco coverage report using Android gradle plugin 0.10.0 or higher?

From Dev

How do I get a jacoco coverage report using Android gradle plugin 0.10.0 or higher?

From Dev

Jacoco Test coverage report shows 0%

From Dev

JaCoCo coverage report setups(exclude test classes)

From Dev

Jacoco Test coverage report shows 0%

From Dev

JaCoCo coverage report setups(exclude test classes)

From Dev

How can I exclude files of the Code Coverage of SonarQube using JaCoCo maven plugin

From Dev

Jenkins jacoco plugin empty report

From Dev

Maven site not link to Jacoco report

From Dev

Generate test coverage with Jacoco and Circle CI fails

From Dev

How to generate jacoco coverage in manual tests?

From Dev

Jacoco Maven multi module project coverage

From Dev

Sonar maven jacoco code coverage for Multimodule project

From Dev

Maven Emma coverage Report failed

From Dev

Maven does not generate a MANIFEST file with maven jar plugin

From Dev

Gradle jacoco coverage report with more than one submodule(s)?

From Dev

Code Coverage Report with Jacoco for IntegrationTests runs on Weblogic server

Related Related

  1. 1

    Generate Code Coverage with JaCoCo and spring-boot-maven-plugin

  2. 2

    maven jacoco: not generating code coverage report

  3. 3

    build.gradle with Jacoco plugin doesn't generate coverage report for integration tests

  4. 4

    maven-surefire-plugin, jacoco-maven-plugin show no coverage

  5. 5

    Jacoco generate coverage report for only a single test class

  6. 6

    Exclude folder in jacoco coverage report

  7. 7

    Jacoco Coverage and Report Task with Ant

  8. 8

    JaCoCo Debug Coverage Test Report

  9. 9

    How to generate xml report with scoverage maven plugin?

  10. 10

    Generate coverage report with stack

  11. 11

    Generate coverage report with stack

  12. 12

    How to report Jacoco Groovy code coverage to Sonar using new Gradle SonarQube plugin?

  13. 13

    How do I get a jacoco coverage report using Android gradle plugin 0.10.0 or higher?

  14. 14

    How do I get a jacoco coverage report using Android gradle plugin 0.10.0 or higher?

  15. 15

    Jacoco Test coverage report shows 0%

  16. 16

    JaCoCo coverage report setups(exclude test classes)

  17. 17

    Jacoco Test coverage report shows 0%

  18. 18

    JaCoCo coverage report setups(exclude test classes)

  19. 19

    How can I exclude files of the Code Coverage of SonarQube using JaCoCo maven plugin

  20. 20

    Jenkins jacoco plugin empty report

  21. 21

    Maven site not link to Jacoco report

  22. 22

    Generate test coverage with Jacoco and Circle CI fails

  23. 23

    How to generate jacoco coverage in manual tests?

  24. 24

    Jacoco Maven multi module project coverage

  25. 25

    Sonar maven jacoco code coverage for Multimodule project

  26. 26

    Maven Emma coverage Report failed

  27. 27

    Maven does not generate a MANIFEST file with maven jar plugin

  28. 28

    Gradle jacoco coverage report with more than one submodule(s)?

  29. 29

    Code Coverage Report with Jacoco for IntegrationTests runs on Weblogic server

HotTag

Archive