【发布时间】:2016-09-05 22:54:06
【问题描述】:
一旦系统允许,我将为此付出巨大的赏金。
我特别遇到的问题是获得覆盖率和让集成测试正常工作。对于这些,我看到了无意义的错误:
Resource not found: com.something.somethingelse.SomeITCase
信息量不足,因为没有什么可以与之相关的,对于没有上下文的人来说也没有多大意义。
这是我看到的另一个怪事。如果子项目没有集成测试,我会看到:
JaCoCoItSensor: JaCoCo IT report not found: /dev/build/dilithium/target/jacoco-it.exec
为什么我会看到target?这不是一个 Maven 项目。全局搜索显示代码库中的任何地方都没有提到target 目录。
然后就是the documentation这一段:
sonarqube {
properties {
properties["sonar.sources"] += sourceSets.custom.allSource.srcDirs
properties["sonar.tests"] += sourceSets.integTest.allSource.srcDirs
}
}
据我所知,sourceSets.integTest.allSource.srcDirs 返回的是文件,而不是字符串。也应该是:
sonarqube {
properties {
property "sonar.tests", "comma,separated,file,paths"
}
请注意,如果其中的目录不存在,则会出现错误。当然,对于将集成测试放在哪个目录以及某些子项目甚至可能不存在,显然没有标准。 Gradle 标准是简单地忽略不存在的目录。您的代码最终看起来像:
sonarqube {
StringBuilder builder = new StringBuilder()
sourceSets.integrationTest.allSource.srcDirs.each { File dir ->
if ( dir.exists() ) {
builder.append(dir.getAbsolutePath())
builder.append(",")
}
}
if (builder.size() > 1) builder.deleteCharAt(builder.size() -1 )
if (builder.size() > 1 )
properties["sonar.tests"] += builder.toString()
properties["sonar.jacoco.reportPath"] +=
"$project.buildDir/jacoco/test.exec,$project.buildDir/jacoco/integrationTest.exec"
}
Sonar 报告根本没有覆盖范围。如果我搜索 *.exec 文件,我会看到我所期望的。那就是:
./build/jacoco/test.exec
./build/jacoco/integrationTest.exec
...但奇怪的是,我也看到了这个:
./build/sonar/com.proj_name_component_management-component_proj-recordstate/jacoco-overall.exec
那是什么?为什么会在这么不规范的位置?
好的,我已经添加了这段代码:
properties {
println "Before: " + properties.get("sonar.tests")
println "Before: " + properties.get("sonar.jacoco.reportPath")
property "sonar.tests", builder.toString()
property "sonar.jacoco.reportPath", "$project.buildDir/jacoco/test.exec,$project.buildDir/jacoco/integrationTest.exec"
println "After: " + properties.get("sonar.tests")
println "After: " + properties.get("sonar.jacoco.reportPath")
}
...导致: [仍在运行]
【问题讨论】:
-
好的,我刚刚发现“找不到资源”意味着在 build/test-results 中找到的 *.xml 结果与其他内容不匹配。 IDK 什么,到目前为止。
-
你发现了吗?
-
确实,我做到了。 :-)