[英]JaCoCo plugin gives different coverage
I'm using the JaCoCo Maven plugin and agent to measure and retrieve the code coverage data of an application which is tested nightly.我正在使用 JaCoCo Maven 插件和代理来测量和检索每晚测试的应用程序的代码覆盖率数据。 This is the schema of the architecture:这是架构的架构:
My Maven project is configured with the JMeter Maven plugin to execute some API tests during the Maven verify
phase.我的 Maven 项目配置了JMeter Maven 插件,以在 Maven verify
阶段执行一些 API 测试。 The Maven command executed by the Jenkins server is the following Jenkins服务器执行的Maven命令如下
mvn verify org.jacoco:jacoco-maven-plugin:0.7.8:dump sonar:sonar -Djacoco.address=TEST_SERVER -Djacoco.destFile=/proj/coverage-reports/jacoco-it.exec -Dsonar.projectKey=sonar_test -Dsonar.projectName=sonar_test -Dsonar.branch=sonar_test -Dsonar.jacoco.itReportPath=/proj/coverage-reports/jacoco-it.exec -Dsonar.java.coveragePlugin=jacoco -Dsonar.language=java
As you can see first the tests are executed through the verify
phase, then the jacoco:dump
goal retrieves the coverage data from the test server (I configured the server to run the JaCoCo agent) and at last the data is uploaded to my Sonar server.正如您所看到的,首先测试是通过verify
阶段执行的,然后jacoco:dump
目标从测试服务器(我将服务器配置为运行 JaCoCo 代理)检索覆盖数据,最后将数据上传到我的声纳服务器.
The "strange" behaviour I'm having is that if I run this command on my computer and then on Jenkins (configuring the Jenkins project accordingly) in the SonarQube page I get different coverage results.我遇到的“奇怪”行为是,如果我在我的计算机上运行此命令,然后在 SonarQube 页面中的 Jenkins(相应地配置 Jenkins 项目)上运行,我会得到不同的覆盖结果。 Moreover, if I configure the Jenkins project and then I simply COPY it creating a new (but equivalent) Jenkins project, the results are different.此外,如果我配置 Jenkins 项目,然后我简单地复制它,创建一个新的(但等效的)Jenkins 项目,结果是不同的。
I tried different configurations and cases, but I cannot understand what the problem can be.我尝试了不同的配置和案例,但我无法理解问题是什么。 Am I not considering some JaCoCo constraints (eg someting related to the Jenkins project name)?我是不是没有考虑一些 JaCoCo 限制(例如与 Jenkins 项目名称相关的一些限制)?
As said in the question comments, the artifact deployed on the test server and the one compiled during the verify
phase on which the report is generated must be exactly the same, so it is not enough that the code is the same.正如问题评论中所说,部署在测试服务器上的工件和生成报告的verify
阶段编译的工件必须完全相同,因此代码相同是不够的。
To solve my problem I had to implement this workflow with Jenkins:为了解决我的问题,我必须用 Jenkins 实现这个工作流程:
mvn package
on the project在项目上做一个mvn package
-Dmaven.compiler.useIncrementalCompilation=false
(thanks to this and this for the hints) in order to not re-compile the artifacts during the verify
phase为此,我必须添加 Maven 标志-Dmaven.compiler.useIncrementalCompilation=false
(感谢this和this的提示),以便在verify
阶段不重新编译工件dump
) the JaCoCo coverage data检索( dump
)JaCoCo 覆盖数据So the Maven command described in the question has been split in two commands: the one which creates the package and the one which performs the tests and retrieves the JaCoCo data without recompiling the artifacts.因此,问题中描述的 Maven 命令已拆分为两个命令:一个创建包,另一个执行测试并检索 JaCoCo 数据,而无需重新编译工件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.