我在互联网上搜索过这个.有很多半的答案在那里,做Maven的属性,如${sonar.jacoco.reportPath},或org.jacoco:jacoco-maven-plugin:prepare-agent或设置maven-surefire-plugin argLine带-javaagent.
一些如何,这些答案,无论是单独的还是组合的,都没有产生我正在追求的东西:一个覆盖率报告,如果它被用于堆栈中更高的测试,例如正在使用的实体,则显示一个类被覆盖通过DAO,即使它没有完全涵盖在自己的模块中的测试.
有没有确定的配置,为了达到这个目的,请?
我正在使用Ant,Jacoco和Sonar.当我运行我的构建时,Sonar告诉我"没有关于每次测试覆盖率的信息." 并且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>
Run Code Online (Sandbox Code Playgroud)
我的声纳目标看起来像这样:
<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 …Run Code Online (Sandbox Code Playgroud) 与SonarQube类似,不会通过Gradle为完全覆盖的类显示每个文件的详细报告,但不会显示欺骗.
Sonar Qube版本3.7.4 Gradle版本2.1
运行gradle sonarRunner生成一个Sonar 确实拾取的文件test.exec
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
Run Code Online (Sandbox Code Playgroud)
然而,在刷新上述项目时,它显示覆盖率为0%
单位测试覆盖率0.0%0.0%线覆盖率0.0%分支覆盖率
我已经设定
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"
}
}
Run Code Online (Sandbox Code Playgroud)
我试过\和正斜杠 - 它没有什么区别
有任何想法吗?
编辑
根据彼得的回答,删除了 …