SonarQube - integrationTest.exec - sonarRunner (Gradle) 或“sonar-runner"命令 - 显示 0.0% 的覆盖率 [英] SonarQube - integrationTest.exec - sonarRunner (Gradle) or "sonar-runner" command - showing 0.0% covereage

查看:25
本文介绍了SonarQube - integrationTest.exec - sonarRunner (Gradle) 或“sonar-runner"命令 - 显示 0.0% 的覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行基于 Gradle 的构建和集成测试后,我在build/jacoco"文件夹中成功生成了 Jacoco 的 2 个 .exec 文件.

I'm successfully generating 2 .exec files by Jacoco within "build/jacoco" folder after running a Gradle based build and integration tests.

Gradle 命令:"gradle clean build integrationTest"

Gradle command: "gradle clean build integrationTest"

完成后,它会在 build/jacoco 文件夹下生成以下 .exec 文件.

Once done, it generates the following .exec files under build/jacoco folder.

  1. test.exec
  2. integrationTest.exec

以下是我的 sonar-project.properties 文件.当我从 Linux 提示符运行sonar-runner"时,它会完成,但在该项目的 SonarQube 仪表板上,我看到单元测试显示为 34.5%,但集成测试显示为 0.0%.两个 .exec 文件都有有效的大小.我还在 .exec 文件上执行了cat",并将输出通过管道传输到 Linux 中的strings"命令,并看到 integrationTest.exec 确实命中了测试函数——我只有 1 个 .java 文件.

Following is my sonar-project.properties file. When, I run "sonar-runner" from Linux prompt it completes but on SonarQube dashboard for this project, I see Unit test says some 34.5% but integration tests says 0.0%. Both .exec files have valid size. I also did "cat" on the .exec files and piped the output to "strings" command in Linux and saw that integrationTest.exec did hit the Tests functions - I have only 1 .java file.

当我运行gradle clean build integrationTest sonarRunner -Dxxx.xxx=yyy -Dyyy.xx=zzz"时,即通过使用 -D 选项传递 sonar-project.properties 文件中提到的所有声纳变量,它可以工作,但是SonarQube 项目的仪表板上的结果相同.项目的声纳仪表板具有为单元/集成测试配置的两个小部件,我包括 IT 测试以显示整体覆盖率.总体覆盖率显示为 34.5%(这是单元测试百分比值).Sonar 确实会看到 test.exec、integrationTest.exec 并且在此操作期间也会自动生成overall-xxx.exec 文件.

When I run "gradle clean build integrationTest sonarRunner -Dxxx.xxx=yyy -Dyyy.xx=zzz" i.e. by passing all the sonar variable as mentioned in the sonar-project.properties file using -D option, it works but same result on SonarQube project's dashboard. Project's sonar dashboard has both widgets configured for Unit / Integration Tests and I'm including IT tests for showing Overall coverage. Overall coverage is showing 34.5% (which is Unit test % value). Sonar does see test.exec, integrationTest.exec and also auto generates overall-xxx.exec file as well during this operation.

注意:我不知道在哪里 - 在单独的 putty/linux 控制台上启动 tomcat 时 - 或者在 Gradle 构建脚本中,为 Jacoco 提供任何值或设置 JAVA 代理.我已经获得了 integrationTest.exec 文件和 test.exec 文件,因此不确定 IT 测试完成运行后是否需要停止 JVM.我不认为我需要这些,因为我有 .exec 文件的有效文件大小.

NOTE: I'm no where - while starting tomcat on a separate putty / linux console -OR within Gradle build script, providing any value or setting JAVA Agent for Jacoco. I'm getting integrationTest.exec file and test.exec file already so not sure if JVM needs to be stopped once IT tests are complete running. I don't think I need those as i have valid file size for .exec files.

我的?:- 为什么即使我正确设置/传递了以下变量,声纳也没有在仪表板上获得 IT 覆盖:

My ?: - Why sonar is not getting IT coverage on the dashboard even though I'm setting / passing the following variable correctly:

sonar.jacoco.itReportPath=build/jacoco/integrationTest.exec

-bash-3.2$ cat sonar-project.properties

-bash-3.2$ cat sonar-project.properties

# Root project information
sonar.projectKey=com:company:product:ProjectA
sonar.projectName=ProjectA
sonar.projectVersion=1.0
# optional description
sonar.projectDescription=ProjectA Service

#Tells SonarQube that the code coverage tool by unit tests is JaCoCo
sonar.java.coveragePlugin=jacoco

#Tells SonarQube to reuse existing reports for unit tests execution and coverage reports
sonar.dynamicAnalysis=reuseReports

# Some properties that will be inherited by the modules
sonar.sources=src/java,test/java,src/java-test

# Sonar Unit Test Report path
sonar.jacoco.reportPath=build/jacoco/test.exec

# Sonar Integration Test Report Path
sonar.jacoco.itReportPath=build/jacoco/integrationTest.exec

sonar.junit.reportsPath=build/UT/results

# Sonar Binaries
sonar.binaries=build/classes/main

推荐答案

缩小原因:我认为是由于集成测试的 .exec 文件.为了证明这一点:我将 UT exex 文件传递​​给 Sonar 变量中的两个报告路径,即以下和 SonarQube 选择了 UT/IT 测试覆盖率.这证明如果用于 IT 测试的 .exec 文件很好(我认为它是好的,但我需要仔细检查),那么 Sonar 将选择 .exec 文件并显示有效的覆盖率 % 而不是 0.0%.注意:以下只是为了证明 Sonar 是否选择了这些值.itReportPath 变量应该使用 Jacoco 集成测试生成的 .exe 文件.

Narrowing down the cause: I think it's due to the .exec file for Integration test. To proove it: I passed UT exex file to both reportsPaths in Sonar variables i.e. the following and SonarQube picked both UT/IT test coverage. This prooves that if .exec file for IT tests is good (which I think it's But I need to double check) then Sonar will pick the .exec file and show a valid coverage % instead of 0.0%. Note: the following is just to proove if Sonar is picking the values or not. itReportPath variable should use the .exe file which is generated by Integration tests by Jacoco.

sonar.jacoco.reportPath=build/jacoco/test.exec

# Sonar Integration Test Report Path
#sonar.jacoco.itReportPath=build/jacoco/testintegrationTest.exec
sonar.jacoco.itReportPath=build/jacoco/test.exec

OK 发现问题.我在 Gradle 中运行 integrationTest 任务,并且没有将 jacocoagent.jar(根据 Jacoco 文档)附加到目标 JVM(Tomcat 的实例)范围.一旦我这样做了,我从 Gradle 中的 integrationTest 任务中删除了 jacoco { ... } 部分(build.gradle 或 GRADLE_HOME/init.d/some.common.gradle 文件,因为这会将 jacoco 代理附加到运行 Gradle 的 Java JVM).现在,一旦将 jacocoagent.jar 附加到 Tomcat 的 JVM(根据我在 Tomcat 的 startup.sh 脚本中添加的下面的行并将变量添加到启动 Tomcat 的命令中),然后我运行 Gradle (integrationTest) 任务来运行 IT 测试.

OK Found the issue. I was running integrationTest task in Gradle and was NOT attaching the jacocoagent.jar (as per Jacoco documentation) to the target JVM (Tomcat's instance) scope. Once I did that, I removed jacoco { ... } section from integrationTest task in Gradle (build.gradle or GRADLE_HOME/init.d/some.common.gradle file as this attach jacoco agent to the Java JVM in which Gradle is running). Now, once jacocoagent.jar was attached to Tomcat's JVM (as per the line below which I added in Tomcat's startup.sh script and added the variable to the command which starts Tomcat), then I ran Gradle (integrationTest) task for running IT tests.

PROJ_EXTRA_JVM_OPTS=-javaagent:tomcat/jacocoagent.jar=destfile=build/jacoco/IT/jacocoIT.exec,append=false

然后,当 Gradle 正在进行时,测试运行了,我得到了一个文件(在给定位置的 jacocoIT.exec),它有一些文件大小,但这还不是最后一个.我必须通过运行 Tomcat 的 stop.sh 脚本来停止 Tomcat 会话/JVM 实例.一旦 Tomcat 停止,我看到 jacocoIT.exec 文件大小显着增加,这是有效的最终 jacocoIT.exec 文件(我需要 sonarRunner Gradle 任务或 sonar-runner 可执行文件来选择并成功将 IT 代码覆盖率数据推送到项目的声纳仪表板).完成后,我得到了 UT + IT 和组合代码覆盖率.

Then while Gradle was in progress, tests ran and I got a file (jacocoIT.exec at the given location) with some file size BUT this is not yet the final one. I had to stop the Tomcat session/JVM instance by running Tomcat's stop.sh script. Once Tomcat was stopped, I saw jacocoIT.exec file size increased significantly and this was the valid final jacocoIT.exec file (which I needed for sonarRunner Gradle task OR sonar-runner exectuable to pick and successfully push IT code coverage data to project's sonar dashboard). Once done, I got both UT + IT and it's combined code coverage.

sonar.jacoco.reportPath=build/jacoco/UT/jacocoUT.exec
sonar.jacoco.itReportPath=build/jacoco/IT/jacocoIT.exec

这篇关于SonarQube - integrationTest.exec - sonarRunner (Gradle) 或“sonar-runner"命令 - 显示 0.0% 的覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆