SonarQube不通过Gradle显示完整覆盖类的每个文件的详细报告 [英] SonarQube does not display detailed report per file for fully covered classes via Gradle

查看:194
本文介绍了SonarQube不通过Gradle显示完整覆盖类的每个文件的详细报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IntelliJ Java IDE中运行Gradle构建。 ) p>

这是我的build.gradle:

 存储库{
mavenCentral()
}

套用插件:'java'
套用插件:'jacoco'
套用插件:'sonar-runner'

sourceCompatibility = 1.7
project.version ='1.0'
project.group ='com.acme.sandbox'
project.description ='只是一个测试项目'

依赖关系{
testCompile组:'junit',name:'junit',版本:'4.11'
}

// JaCoCo测试覆盖配置
tasks.withType(Test){task - >
jacoco {
append = false
}
}

//声纳配置
sonarRunner {
sonarProperties {
属性'sonar.host.url','http:// host:port'
属性'sonar.jdbc.url','myJdbcURL'
属性'sonar.jdbc.username','dbuser '
属性'sonar.jdbc.password','dbpass'
属性'sonar.login','builduser'
属性'sonar.password','buildpass'

属性'sonar.profile','profilename'
属性'sonar.branch','DEV'$ b $属性'sonar.language','java'$ b $属性'sonar.sourceEncoding ','UTF-8'
属性'sonar.verbose','true'
//属性'sonar.tests',$ projectDir \\\\ src\\test\\\ \\ java
// property'sonar.binaries',$ {buildDir} \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\',$ { b
//属性'sonar.java.coveragePlugin','jacoco'
属性'sonar.jacoco.reportPath',$ {buildDir} \\jacoco\\test.exec
property'sonar.junit.reportsPath',$ {buildDir} \\ test-results
}
}

现在,如果执行 clean ,然后执行 sonarRunner ,JaCoCo test.exec 文件被创建并处理: $ b

  <剪断> 
18:35:27.705 DEBUG - 初始化程序:
18:35:27.706信息 - 基本目录:D:\路径\ to\JaCoCoTest
18:35:27.706信息 - 工作dir:D:\path\to\JaCoCoTest\build\sonar
18:35:27.707信息 - 来源目录:D:\路径\\\\JaCoCoTest\src\main \java
18:35:27.708 INFO - 测试目录:D:\path\to\JaCoCoTest\src\test\java
18:35:27.708信息 - 二进制代码:D:\路径\到\JaCoCoTest\build\classes\main
< snip>
18:35:27.931信息 - 未找到JaCoCo IT报告。
18:35:27.933信息 - 未找到JaCoCo报告。
18:35:27.938 DEBUG - 传感器:JavaSquidSensor - > QProfileSensor - > FindbugsSensor - > CpdSensor - > PmdSensor - > SurefireSensor - > CheckstyleSensor - > InitialOpenIssuesSensor - > ProfileEventsSensor - > ProjectLinksSensor - > VersionEventsSensor - > FileHashSensor - > JaCoCoSensor
< snip>
18:35:34.055信息 - 传感器SurefireSensor ...
18:35:34.056 INFO - 解析D:\path\to\JaCoCoTest\build\test- results
18:35:34.116信息 - 传感器SurefireSensor完成:61 ms
< snip>
18:35:34.936信息 - 传感器JaCoCoSensor ...
18:35:34.939 INFO - 分析D:\路径\ to\JaCoCoTest\build\jacoco\test.exec
18:35:35.027信息 - 没有关于每个测试覆盖率的信息。
18:35:35.028信息 - 传感器JaCoCoSensor完成:92 ms

这篇文章建议设置 sonar.tests ,我试过没有效果。该日志文件显示测试源和二进制文件被检测到位于正确的位置。

FWIW,我在Maven构建中使用了相同的设置并且工作正常。
$ b 版本号:


  • SonarQube 4.3

  • SonarQube Java Ecosystem 2.2.1

  • Gradle 1.12(又见:1.11)

  • IntelliJ IDEA Ultimate 13.1 .3

  • Java 1.7



以下是完整测试项目以供下载,同时完整日志 解决方案

这就是所谓的'通缉'行为。声纳不显示100%覆盖率的课程。在你的项目中,你有一个课程完全覆盖了测试,所以没什么可显示的。

供参考:



如果你有100%的覆盖课程,你可以通过搜索声纳搜索框(右上角)来查看这个课程的覆盖面。




如果您看到 .exec 并且它的大小很有限,那么您已经收集了覆盖率数据。

查看我的常见问题



我得到了这个代码分析小工具您的项目:



最后在我添加了另一个测试发现的方法后,测试覆盖率降至80%:



我得到了你需要的东西 - 按行覆盖:



顺便说一下,你的mod ifard build.gradle 我的声纳( // 不适用于我):

 存储库{
mavenCentral()
}

应用插件:'java'
apply plugin:'jacoco'
套用插件:'sonar-runner'


sourceCompatibility = 1.7
project.version ='1.0'
project.group ='com.acme .sandbox'
project.description ='只是一个测试项目'

依赖项{
testCompile组:'junit',名称:'junit',版本:'4.11'
}

// JaCoCo测试覆盖配置
tasks.withType(测试){任务 - >
jacoco {
append = false
}
}

//声纳配置
sonarRunner {
sonarProperties {
//有关SonarQube服务器的一般信息
属性'sonar.host.url','http:// localhost:9000'
属性'sonar.jdbc.url','jdbc:h2:tcp :// localhost:9092 / sonar'
属性'sonar.jdbc.validationQuery','select 1'
属性'sonar.jdbc.driverClassName','org.hibernate.dialect.H2Dialect'
属性'sonar.jdbc.password','sonar'
属性'sonar.jdbc.password','sonar'
属性'sonar.login','jenkins'
属性' sonar.password','jenkins'

//关于这个项目的信息
//属性'sonar.profile','profilename'
属性'sonar.branch',' DEV'
属性'sonar.language','java'
属性'sonar.sourceEncoding','UTF-8'
属性'sonar.verbose','true'
//属性'sonar.tests',$ projectDir\\src\\\ \\ test \\java
属性'sonar.binaries',$ {buildDir} / classes / main /

//在SonarQube运行之前执行JaCoCo以创建报告文件准备
//属性'sonar.java.coveragePlugin','jacoco'
属性'sonar.jacoco.reportPath',$ {buildDir} /jacoco/test.exec
property' sonar.junit.reportsPath',$ {buildDir} / test-results
}
}


I am running a Gradle build inside the IntelliJ Java IDE. The SonarQube runner Gradle plugin is used along with the JaCoCo Gradle plugin.

Problem: I am getting the message No information about coverage per test., (not a duplicate of this post, see below) and the coverage appears in SonarQube, but only as an overall percentage, not a detailed report per file:

Am I doing something wrong? Is it a bug in SonarQube maybe (as it was with Cobertura recently)?

Here is my build.gradle:

repositories {
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'sonar-runner'

sourceCompatibility = 1.7
project.version = '1.0'
project.group = 'com.acme.sandbox'
project.description = 'just a test project'

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

// JaCoCo test coverage configuration
tasks.withType(Test) { task ->
    jacoco {
        append = false
    }
}

// Sonar configuration
sonarRunner {
  sonarProperties {
    property 'sonar.host.url', 'http://host:port'
    property 'sonar.jdbc.url', 'myJdbcURL'
    property 'sonar.jdbc.username', 'dbuser'
    property 'sonar.jdbc.password', 'dbpass'
    property 'sonar.login', 'builduser'
    property 'sonar.password', 'buildpass'

    property 'sonar.profile', 'profilename'
    property 'sonar.branch', 'DEV'
    property 'sonar.language', 'java'
    property 'sonar.sourceEncoding', 'UTF-8'
    property 'sonar.verbose', 'true'
    //property 'sonar.tests', "$projectDir\\src\\test\\java"
    //property 'sonar.binaries', "${buildDir}\\classes\\main,${buildDir}\\classes\\test"

    //property 'sonar.java.coveragePlugin', 'jacoco'
    property 'sonar.jacoco.reportPath', "${buildDir}\\jacoco\\test.exec"
    property 'sonar.junit.reportsPath', "${buildDir}\\test-results"
  }
}

Now if you execute a clean, followed by sonarRunner, a JaCoCo test.exec file gets created and processed:

<snip>
18:35:27.705 DEBUG - Initializers : 
18:35:27.706 INFO  - Base dir: D:\path\to\JaCoCoTest
18:35:27.706 INFO  - Working dir: D:\path\to\JaCoCoTest\build\sonar
18:35:27.707 INFO  - Source dirs: D:\path\to\JaCoCoTest\src\main\java
18:35:27.708 INFO  - Test dirs: D:\path\to\JaCoCoTest\src\test\java
18:35:27.708 INFO  - Binary dirs: D:\path\to\JaCoCoTest\build\classes\main
<snip>
18:35:27.931 INFO  - JaCoCo IT report not found.
18:35:27.933 INFO  - JaCoCo reports not found.
18:35:27.938 DEBUG - Sensors : JavaSquidSensor -> QProfileSensor -> FindbugsSensor -> CpdSensor -> PmdSensor -> SurefireSensor -> CheckstyleSensor -> InitialOpenIssuesSensor -> ProfileEventsSensor -> ProjectLinksSensor -> VersionEventsSensor -> FileHashSensor -> JaCoCoSensor
<snip>
18:35:34.055 INFO  - Sensor SurefireSensor...
18:35:34.056 INFO  - parsing D:\path\to\JaCoCoTest\build\test-results
18:35:34.116 INFO  - Sensor SurefireSensor done: 61 ms
<snip>
18:35:34.936 INFO  - Sensor JaCoCoSensor...
18:35:34.939 INFO  - Analysing D:\path\to\JaCoCoTest\build\jacoco\test.exec
18:35:35.027 INFO  - No information about coverage per test.
18:35:35.028 INFO  - Sensor JaCoCoSensor done: 92 ms

This post suggests to set sonar.tests, which I've tried to no effect. The log file shows that test sources and binaries are detected to be at the correct locations.

FWIW, I used the same settings with a Maven build and it worked. Can't use Maven here though.

Version numbers:

  • SonarQube 4.3
  • SonarQube Java Ecosystem 2.2.1
  • Gradle 1.12 (also: 1.11)
  • IntelliJ IDEA Ultimate 13.1.3
  • Java 1.7

Here is the full test project for download, and also the full log.

解决方案

This is what is called 'wanted' behaviour. Sonar does not display classes with 100% coverage. In your project you have one class fully covered by tests, so nothing to show.

FYI:

Even if you have 100% covered class, you can look at this class coverage by searching in sonars search box (top-right corner).


If you see .exec and it is of valuable size, then you already collected coverage data.

See my FAQ

I got this code analysis widget for your project:

And finally after I added another method uncovered by tests and test coverage dropped to 80%:

I got what you need - coverage by line:

By the way, your modified build.gradle for my sonar (this // does not work for me):

repositories {
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'sonar-runner'


sourceCompatibility = 1.7
project.version = '1.0'
project.group = 'com.acme.sandbox'
project.description = 'just a test project'

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

// JaCoCo test coverage configuration
tasks.withType(Test) { task ->
    jacoco {
        append = false
    }
}

// Sonar configuration
sonarRunner {
    sonarProperties {
        // general information about the SonarQube server
        property 'sonar.host.url', 'http://localhost:9000'
        property 'sonar.jdbc.url', 'jdbc:h2:tcp://localhost:9092/sonar'
        property 'sonar.jdbc.validationQuery', 'select 1'
        property 'sonar.jdbc.driverClassName', 'org.hibernate.dialect.H2Dialect'
        property 'sonar.jdbc.password', 'sonar'
        property 'sonar.jdbc.password', 'sonar'
        property 'sonar.login', 'jenkins'
        property 'sonar.password', 'jenkins'

        // information about this project
        //property 'sonar.profile', 'profilename'
        property 'sonar.branch', 'DEV'
        property 'sonar.language', 'java'
        property 'sonar.sourceEncoding', 'UTF-8'
        property 'sonar.verbose', 'true'
        //property 'sonar.tests', "$projectDir\\src\\test\\java"
        property 'sonar.binaries', "${buildDir}/classes/main/"

        // execute JaCoCo before the SonarQube run to have report file ready
        //property 'sonar.java.coveragePlugin', 'jacoco'
        property 'sonar.jacoco.reportPath', "${buildDir}/jacoco/test.exec"
        property 'sonar.junit.reportsPath', "${buildDir}/test-results"
    }
}

这篇关于SonarQube不通过Gradle显示完整覆盖类的每个文件的详细报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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