java “没有关于每次测试覆盖率的信息。” 从声纳与 Jacoco Ant 构建
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16615558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"No information about coverage per test." from Sonar with Jacoco Ant build
提问by Paul Grenyer
I'm using Ant, Jacoco and Sonar. When I run my build Sonar tells me that "No information about coverage per test." and the Sonar dashboard has my coverage results, but I cannot drill down into them to see the code. However, the HTML report generated by Jacoco does include drill down into the code. This is my coverage task:
我正在使用 Ant、Jacoco 和 Sonar。当我运行我的构建时,声纳告诉我“没有关于每个测试覆盖率的信息”。并且声纳仪表板有我的覆盖结果,但我无法深入查看代码。但是,Jacoco 生成的 HTML 报告确实包含深入到代码中的内容。这是我的覆盖任务:
<jacoco:coverage destfile="${coverage.output.file}" >
<junit printsummary="on"
errorProperty="test.failed"
failureProperty="test.failed"
haltonfailure="yes"
fork="true">
<formatter type="brief" usefile="false" />
<formatter type="xml" />
<classpath>
<path refid="test.build.class.path"/>
<pathelement location="${test.bin.dir}"/>
</classpath>
<batchtest todir="${results.dir}">
<fileset dir="${test.bin.dir}">
<include name = "**/**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<jacoco:report>
<executiondata>
<file file="${coverage.output.file}"/>
</executiondata>
<structure name="${ant.project.name}">
<classfiles>
<fileset dir="${bin.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<html destdir="${coverage.results.dir}"/>
</jacoco:report>
</target>
And my Sonar target looks like this:
我的声纳目标看起来像这样:
<target name="sonar" depends = "run">
<property name="sonar.jdbc.url" value="..." />
<property name="sonar.jdbc.username" value="...r" />
<property name="sonar.jdbc.password" value="..." />
<property name="sonar.projectKey" value="org.codehaus.sonar:example-java-ant" />
<property name="sonar.projectName" value="${ant.project.name} (ant)" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="${src.dir}" />
<property name="sonar.binaries" value="${bin.dir},${test.bin.dir}" />
<property name="sonar.libraries" value="${lib.dir}/*.jar" />
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<property name="sonar.surefire.reportsPath" value="${results.dir}" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.jacoco.reportPath" value="${coverage.output.file}" />
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath>
<fileset dir="${lib.dir}" includes="sonar-ant-task-2.0.jar"/>
</classpath>
</taskdef>
<sonar:sonar />
</target>
Does anyone know what I am missing?
有谁知道我错过了什么?
回答by David RACODON - QA Consultant
It looks like you haven't set the 'sonar.tests' property to tell Sonar where to find the source code of your unit tests. See http://docs.sonarqube.org/display/SONAR/Analysis+Parameters.
看起来您还没有设置 'sonar.tests' 属性来告诉 Sonar 在哪里可以找到单元测试的源代码。请参阅http://docs.sonarqube.org/display/SONAR/Analysis+Parameters。
David RACODON | SonarSource
大卫拉科顿 | 声纳源
回答by HankCa
The sonar.test
property should be set to the test-classes. We have the following in our maven pom. For ANT you do something similar:
该sonar.test
属性应设置为测试类。我们的 maven pom.xml 文件中有以下内容。对于 ANT,您可以执行类似的操作:
<profile>
<id>sonarprofile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>....our host..../sonar.host.url>
<sonar.projectKey>....our key....</sonar.projectKey>
<sonar.projectName>${project.artifactId}</sonar.projectName>
<sonar.projectVersion>${project.version}</sonar.projectVersion>
<sonar.language>java</sonar.language>
<sonar.sources>src/main/java</sonar.sources>
<!-- sonar.tests>target/test-classes</sonar.tests -->
<!-- that is the default location for Maven projects and -->
<!-- this parameter can't actually be set in that case -->
<sonar.scm.provider>git</sonar.scm.provider>
<sonar.login>${SONAR_LOGIN}</sonar.login>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.reportPath>${basedir}/target/coverage-reports/jacoco-unit.exec</sonar.jacoco.reportPath>
</properties>
</profile>
Incidently there are some other properties being used in this:
顺便说一下,这里还使用了一些其他属性:
- I've generated a SONAR token through my sonar user rather than use login and password
- JaCoCo coverage is being generated separately using the
jacoco-maven-plugin
and thesonar.jacoco.reportPath
is a property used in that plugin.
- 我通过我的声纳用户生成了一个 SONAR 令牌,而不是使用登录名和密码
- JaCoCo 覆盖率是使用
jacoco-maven-plugin
和sonar.jacoco.reportPath
是该插件中使用的属性单独生成的。
David Racodon's answer (https://stackoverflow.com/a/16645108/1019307) was once correct but in mid-2014 SonarQube stopped executing the tests as part of the sonar execution (http://www.sonarqube.org/unit-test-execution-in-sonarqube/). Hence why pointing to the test source no longer works.
David Racodon 的回答 ( https://stackoverflow.com/a/16645108/1019307) 曾经是正确的,但在 2014 年年中 SonarQube 停止执行测试作为声纳执行的一部分 ( http://www.sonarqube.org/unit- test-execution-in-sonarqube/)。因此,为什么指向测试源不再有效。