没有单位测试成功报告声纳 [英] No unit test success reported to sonar

查看:131
本文介绍了没有单位测试成功报告声纳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gradle build正在创建一个由声纳亚军拾起的jacoco报告。将声纳结果推入声纳服务器后,即使所有测试都成功运行,单元测试覆盖率也会显示,但单元测试成功率为0. 观看声纳亚军日志我看到以下项目报告源和类位置:

  15:52:36.087 INFO  - 源代码目录:/ poc- sonar / src / main / java 
15:52:36.087信息 - 测试目录:/ 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

这引发了第一个问题:Sonar是否必须查看编译的测试类进行分析?



进一步向下:

  15:52:37.435信息 - 传感器JaCoCoSensor ... 
15:52:37.445信息 - 分析/poc-sonar/build/jacoco/test.exec
15:52:37.546信息 - 没有关于每个测试覆盖率的信息。
15:52:37.548信息 - 传感器JaCoCoSensor完成:113 ms
15:52:38.105 INFO - 执行装饰器...
15:52:38.580 INFO - 将结果存储在数据库$ b中$ b



Jacoco选择了 test.exec 文件,但报告没有关于每次测试覆盖率的信息



该日志语句的含义是什么?声纳服务器实际上暴露了正确的覆盖范围!这是Sonar报告失败测试成功的指标吗?什么是缺少获得单位

 单元测试覆盖
50,0%
50,0%在线覆盖率

单元测试成功
0测试

完整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'
申请插件:'sonar-runner'

group =poc
version =1.0.0-SNAPSHOT

sourceCompatibility = 1.7
targetCompatibility = 1.7

存储库{
maven {
凭证{
username$ {artifactoryUsername}
密码$ {artifactoryPassword}

url$ {artifactoryContextUrl}
}
}

依赖关系{
testCompilejunit:junit- dep:4.11
testCompileorg.codehaus.gro ovy:groovy-all:$ groovyVersion
testCompileorg.spockframework:spock-core:$ spockVersion


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

sonarRunner {
sonarProperties {
属性'sonar.projectName',rootProject.name
属性'sonar.projectDescription',rootProject.name

//声纳服务器和数据库
属性sonar.host.url,sonarHostUrl
属性sonar.jdbc.url,sonarJdbcUrl
//属性sonar.jdbc.driverClassName,com.mysql.jdbc.Driver
属性sonar.jdbc.username,sonarJdbcUsername
属性sonar.jdbc.password,sonarJdbcPassword
属性'sonar.sourceEncoding','UTF-8'
}
}

tasks.sonarRunner.dependsOn = []


解决方案在最近的Sonar版本中,测试报告位置的Sonar属性已从 sonar.surefire.reportsPath 更名为 sonar.junit。 reportsPath 。因此您可能需要手动设置后者。例如:

 应用插件:sonar

子项目{
apply plugin: java
sonarRunner {
sonarProperties {
属性sonar.junit.reportsPath,test.reports.junitXml.destination
}
}
}


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 = []

解决方案

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
        }
    }
}

这篇关于没有单位测试成功报告声纳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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