Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar does not pick up test coverage information

Similar to SonarQube does not display detailed report per file for fully covered classes via Gradle but not a dupe.

Sonar Qube version 3.7.4 Gradle version 2.1

Running the gradle sonarRunner generates a file test.exec which Sonar does pick up

14:50:28.167 INFO  - Analysing D:\projname\build\jacoco\test.exec
14:50:28.265 INFO  - No information about coverage per test.
14:50:28.266 INFO  - Sensor JaCoCoSensor done: 106 ms
14:50:28.529 INFO  - Execute decorators...
14:50:29.253 INFO  - Store results in database
14:50:29.391 INFO  - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/com.projname

However on refreshing the said project it shows coverage at 0%

Unit Tests Coverage 0.0% 0.0% line coverage 0.0% branch coverage

I have set

sonarRunner {
    sonarProperties {
        property 'sonar.jacoco.reportPath', 'D:\\projname\\build\\jacoco\\test.exec'
        property 'sonar.junit.reportsPath','$buildDir/test-results'
        property 'sonar.tests', "$buildDir/classes/test"
     }
}

I have tried \ and forward slashes - it does not make a difference

any ideas?

EDIT

As per Peter's answer, removed the sonarProperties - so build.gradle basically is

subprojects {
   apply plugin: 'java'
   apply plugin: 'eclipse'
   apply plugin: 'sonar-runner'
   apply plugin: 'jacoco'
   sourceCompatibility  = 1.7
   group = 'com.mycomp'
   version = '1.0-SNAPSHOT'

    repositories {
        mavenCentral()
    }

    dependencies {
        testCompile 'junit:junit:4.10'
    }
}

This does not read the default exec file which is generated at D:\projname\build\jacoco\test.exec

Instead it gives the message

17:06:36.912 INFO  - Project coverage is set to 0% as no JaCoCo execution data has been dumped: D:\projname\target\jacoco.exec

Question: Does spaces in folder names cause a problem

like image 224
shinynewbike Avatar asked Nov 11 '14 10:11

shinynewbike


People also ask

Does SonarQube provide test coverage?

SonarQube supports the reporting of test coverage as part of the analysis of your Java project. However, SonarQube does not generate the coverage report itself. Instead, you must set up a third-party tool to produce the report as part of your build process.

How do I show code coverage in Sonar?

SonarQube in Action Then we'll start the SonarQube server before running the command mvn sonar:sonar. Once this command runs successfully, it will give us a link to the dashboard of our project's code coverage report: Notice that it creates a file named jacoco. exec in the target folder of the project.

What helps get per exam coverage in SonarQube?

Coverage per tests For Java projects using JaCoCo, it's possible to have "coverage per test" information. This includes: Displaying the number of different tests that cover a specific line.

Why does JaCoCo not show coverage?

Why does the coverage report not show highlighted source code? Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports: Class files must be compiled with debug information to contain line numbers. Source files must be properly supplied at report generation time.


1 Answers

Use gradle test sonarRunner to make sure that test and coverage results are up-to-date. Avoid absolute paths in build scripts. Groovy only performs String interpolation for double-quoted strings ("$buildDir/test-results"). If you have the jacoco and java plugins applied, all the Sonar properties shown in your snippet should be preconfigured correctly.

like image 112
Peter Niederwieser Avatar answered Oct 15 '22 05:10

Peter Niederwieser