SonarQube does not display detailed report per file for fully covered classes via Gradle

瘦欲@ 提交于 2019-12-05 10:17:44
ZuzEL

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"
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!