Code coverage 0% by unit tests

Hello!

Must-share information (formatted with Markdown):

  • SonarQube 6.7.4
  • Code coverage by unit tests
  • mvn sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=…

My pom.xml:

<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.itReportPath>target/coverage-reports/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.jacoco.reportPath>target/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPath>
<sonar.junit.reportPath>target/surefire-reports</sonar.junit.reportPath>
<sonar.jacoco.listeners.version>3.2</sonar.jacoco.listeners.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.language>java</sonar.language>
<sonar.maven.plugin.version>3.4.0.905</sonar.maven.plugin.version>
<jacoco.outputDir>${project.build.directory}</jacoco.outputDir>

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.3</version>
    <executions>
        <execution>
            <id>prepare-ut-agent</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <destFile>target/coverage-reports/jacoco-ut.exec</destFile>
                <propertyName>jacoco.agent.ut.arg</propertyName>
                <append>true</append>
            </configuration>
        </execution>
    <execution>
        <id>prepare-it-agent</id>
        <phase>pre-integration-test</phase>
        <goals>
            <goal>prepare-agent</goal>
        </goals>
        <configuration>
            <destFile>target/coverage-reports/jacoco-it.exec</destFile>
            <propertyName>jacoco.agent.it.arg</propertyName>
            <append>true</append>
        </configuration>
    </execution>
</executions>

Can you help me please? =)

Hello Alexandr,

First of all, could you please share which version of sonar-java you are using, that would help narrow the issue you are facing, thanks.

When I look at what you reported, what strikes me is the following: properties sonar.jacoco.itReportPath, sonar.jacoco.reportPath, and sonar.junit.reportPath have all been deprecated.
Instead of sonar.jacoco.itReportPath and sonar.jacoco.reportPath, you should be using sonar.coverage.jacoco.xmlReportPaths. I would strongly advice you to have a look and follow what is described in the following coverage guide.

What’s more, sonar.junit.reportPath property was deprecated in sonar-java 4.11 and removed in sonar-java 5.12, you should be using sonar.junit.reportPaths instead, which allow for a comma separated list of reports.

If you are still facing issues after trying the above, can you please also share the log of your analysis.

Best,
-Chris

1 Like

I am having the same problem. After switching to JUnit 5, all the code coverage reporting went to 0%. I took the example from https://github.com/SonarSource/sonar-scanning-examples and modified maven-multimodule from JUnit 4, and switched it to JUnit 5. The sample has the same problem.

The only changes made to create the issue was

  1. Changing the test imports to
    import org.junit.jupiter.api.Test;
  2. and changing the pom JUnit dependency to

    org.junit.jupiter
    junit-jupiter-engine
    5.6.0
    test

Hello @Derek

I saw that you opened another topic related to this subject.
Since the original post is quite old and it seems to be related to another problem, creating a new one was the right move.

Bumping this one was not though, please be careful next time!

I will have a look and answer on the other one, please continue the discussion there if needed.

Best,
Quentin

Hey, how you doing?

I have an example project with Junit5 working at https://github.com/GiuseppeMP/JacocoMultiModuleReport

Regards,
Giuseppe

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.