简体   繁体   English

jacoco 插件的 SonarQube 覆盖率百分比显示为零,但可以看到单元测试的数量

[英]SonarQube coverage percentage with jacoco plugin shows zero percentage but hte number of unit tests are seen

I have configured a project in SonarQube and the anlaysis is run using JaCoCo plugin for visualisation of unit test coverage .我已经在 SonarQube 中配置了一个项目,并且分析是使用 JaCoCo 插件运行的,用于单元测试覆盖率的可视化。

The tests are run successfully in Jenkins and the reports can be seen in the Jenkins workspace .测试在 Jenkins 中成功运行,报告可以在 Jenkins 工作区中看到。

However ,sonar dashboard shows the coverage as 0% but the number of unit tests are still seen on sonar dashboard as well .但是,声纳仪表板显示覆盖率为 0%,但单元测试的数量仍然可以在声纳仪表板上看到。 I have tried using the following properties in command line .These properties are configured in the SonarQube configuration as well.我尝试在命令行中使用以下属性。这些属性也在 SonarQube 配置中进行了配置。

-Dsonar.junit.reportsPath=target/surefire-reports  -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml 

在此处输入图片说明

do you have configured jacoco prepare-agent?你有没有配置jacoco prepare-agent? I faced the same issue and have found out, that I missed this configuration.我遇到了同样的问题,并发现我错过了这个配置。

Helpful link for that could be https://docs.sonarqube.org/display/SONARQUBE45/JaCoCo+Plugin .有用的链接可能是https://docs.sonarqube.org/display/SONARQUBE45/JaCoCo+Plugin

Or via pom.xml:或者通过 pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.0</version>
            <configuration>
                <append>true</append>
            </configuration>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Regarding to your report paths:关于您的报告路径:

Which version of SonarQube do you use?您使用哪个版本的 SonarQube?

sonar.junit.reportsPath

is deprecated since version 4.11 and自 4.11 版起已弃用,并且

sonar.junit.reportPaths

should be used instead.应该改用。

And how do you create your xml report file?以及如何创建 xml 报告文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM