Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No unit test success reported to sonar

A gradle build is creating a jacoco report which is picked up by sonar runner. After the sonar results are pushed to the sonar server, unit test coverage is displayed but unit test success is 0 even though all tests are run successfully.

Looking at the sonar runner log I see the following items reporting the source and classes locations:

15:52:36.087 INFO  - Source dirs: /poc-sonar/src/main/java
15:52:36.087 INFO  - Test dirs: /poc-sonar/src/test/java, /Volumes/Disk/Development/poc-sonar/src/test/groovy
15:52:36.088 INFO  - Binary dirs: /poc-sonar/build/classes/main

This is raising the first question: Does Sonar have to see the compiled test classes for analysis?

Further down the log:

15:52:37.435 INFO  - Sensor JaCoCoSensor...
15:52:37.445 INFO  - Analysing /poc-sonar/build/jacoco/test.exec
15:52:37.546 INFO  - No information about coverage per test.
15:52:37.548 INFO  - Sensor JaCoCoSensor done: 113 ms
15:52:38.105 INFO  - Execute decorators...
15:52:38.580 INFO  - Store results in database

Jacoco has picked up the test.exec file, but reporting "No information about coverage per test"

What does that log statement mean? The sonar server actually exposes correct coverage! Is it an indicator for the missing test success reported by Sonar? What is missing for getting the unit

Unit Tests Coverage
50,0%
50,0% line coverage

Unit test success
0 tests 

The full gradle build.script:

ext {
    spockVersion = '0.7-groovy-2.0'
    groovyVersion = '2.2.1'
}

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

group = "poc"
version = "1.0.0-SNAPSHOT"

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    maven {
        credentials {
            username "${artifactoryUsername}"
            password "${artifactoryPassword}"
        }
        url "${artifactoryContextUrl}"
    }
}

dependencies {
    testCompile "junit:junit-dep:4.11"
    testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
    testCompile "org.spockframework:spock-core:$spockVersion"
}

tasks.withType(Test) { task ->
    jacoco {
        destinationFile = file("$buildDir/jacoco/${task.name}.exec")
    }
}

sonarRunner {
    sonarProperties {
        property 'sonar.projectName', rootProject.name
        property 'sonar.projectDescription', rootProject.name

        // sonar server and database
        property "sonar.host.url", sonarHostUrl
        property "sonar.jdbc.url", sonarJdbcUrl
        //property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
        property "sonar.jdbc.username", sonarJdbcUsername
        property "sonar.jdbc.password", sonarJdbcPassword
        property 'sonar.sourceEncoding', 'UTF-8'
    }
}

tasks.sonarRunner.dependsOn = []
like image 216
Martin Ahrer Avatar asked Jan 24 '14 15:01

Martin Ahrer


1 Answers

In recent Sonar versions, the Sonar property for test report location has been renamed from sonar.surefire.reportsPath to sonar.junit.reportsPath. Hence you may have to set the latter manually. For example:

apply plugin: "sonar"

subprojects {
    apply plugin: "java"
    sonarRunner {
        sonarProperties {
            property "sonar.junit.reportsPath", test.reports.junitXml.destination
        }
    }
}
like image 96
Peter Niederwieser Avatar answered Oct 14 '22 10:10

Peter Niederwieser