代码覆盖率未反映在SonarQube UI中
我正在尝试使用SonarQube建立静态代码分析。在SonarQube UI中创建了一个项目。在詹金斯管道内运行声纳扫描仪 管道运行成功,报告已发布到SonarQube,但未显示预期的代码覆盖率: 它显示测试已经找到,但仍然显示覆盖率为0% 我在pom.xml中使用了jacoco插件:代码覆盖率未反映在SonarQube UI中,sonarqube,jenkins-pipeline,jacoco-maven-plugin,Sonarqube,Jenkins Pipeline,Jacoco Maven Plugin,我正在尝试使用SonarQube建立静态代码分析。在SonarQube UI中创建了一个项目。在詹金斯管道内运行声纳扫描仪 管道运行成功,报告已发布到SonarQube,但未显示预期的代码覆盖率: 它显示测试已经找到,但仍然显示覆盖率为0% 我在pom.xml中使用了jacoco插件: <pluginManagement> <plugins> <plugin> <groupId>org.j
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
</plugin>
</plugins>
</pluginManagement>
org.jacoco
jacocomaven插件
0.8.6
我在管道内运行jacoo:prepare代理和jacoco:report。甚至在运行jacoco目标之前尝试运行mvn clean install,但没有用
还要检查在target/surefire报告下生成的xml文件,该报告显示测试已运行:
测试集:in.javahome.myweb.controller.CalculatorTest 测试运行:2,失败:0,错误:0,跳过:0,所用时间:0.047秒 SonarQube版本:7.9.4 詹金斯版本:2.259 任何关于问题所在的指示都将不胜感激
谢谢这通常意味着您没有将jacoco插件与surefire插件正确集成。获得代码覆盖率结果的唯一方法是,如果surefire以生成代码覆盖率数据的方式运行。默认情况下,它们不会集成在一起 这两个插件的重要部分如下:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.maven.plugin.version}</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>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
org.jacoco
jacocomaven插件
${jacoco.maven.plugin.version}
单元前测试
配制剂
surefireArgLine
这是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin.version}
${surefireArgLine}
能够使用surefire插件生成代码覆盖率。谢谢@David M.Karr