无法使用Jacoco ant和SonarQube查看代码覆盖率结果
我想在SonarQube 3.2.1中查看测试覆盖率报告,但什么也看不到,并且在我的构建中出现以下错误:无法使用Jacoco ant和SonarQube查看代码覆盖率结果,ant,jenkins,jacoco,sonarqube,Ant,Jenkins,Jacoco,Sonarqube,我想在SonarQube 3.2.1中查看测试覆盖率报告,但什么也看不到,并且在我的构建中出现以下错误: 00:11:17.747 INFO o.s.p.j.JaCoCoPlugin - Analysing /home/jenkins/workspace/.../build/codeCoverageReport/jacoco.exec 00:11:17.795 WARN o.s.p.j.JaCoCoPlugin - Coverage information was not collected
00:11:17.747 INFO o.s.p.j.JaCoCoPlugin - Analysing /home/jenkins/workspace/.../build/codeCoverageReport/jacoco.exec
00:11:17.795 WARN o.s.p.j.JaCoCoPlugin - Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
我执行Jacoco Ant报告任务:
<target name="compile-tests" depends="compile">
<javac includeantruntime="false"
debug="true" debuglevel="lines,vars,source"
executable="${jdk1.5.home}/bin/javac"
fork="true"
srcdir="${src-test.dir}" destdir="${build-test.dir}"
classpathref="classpath-test"
encoding="UTF-8"
/>
</target>
<target name="whatever">
<jacoco:coverage destfile="${workspace.dir}/build/codeCoverageReport/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant">
<junit fork="true" jvm="${jdk1.5.home}/jre/bin/java" printsummary="yes" forkmode="once">
<classpath>
<path refid="classpath-test"/>
<path location="${build-test.dir}"/>
</classpath>
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest todir="${workspace.dir}/42-SSW/build/tuReport">
<fileset dir="${src-test.dir}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
有什么想法吗?在您的错误日志中说:
00:11:17.795 WARN o.s.p.j.JaCoCoPlugin - Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
看看你的ant脚本,你似乎用调试信息编译了你的测试源代码。您是否也编译了测试中包含调试信息的源代码
由于这似乎是一个与jacoco相关的问题,我还要向您介绍jacoco常见问题:
面临同样的问题。通过做以下更改,我能够在sonar中获得覆盖范围
<property name="sonar.core.coveragePlugin" value="jacoco" />
<property name="sonar.junit.reportsPath" value="${build.dir}/test-report"/>
<property name="sonar.jacoco.reportPath" value="${build.dir}/jacoc.exec" />
在“编译”目标中包含调试信息
您是否查看了我们的示例项目以比较您的项目?=>这可以帮助你,是的。我不使用声纳蚂蚁任务,因为詹金斯为我提供了它。我看到的唯一“大”区别是,我编译的“.class”在TU类和测试类之间有不同的位置。我将检查是否存在错误的零覆盖率问题,打开debug=“true”
对我有效
<property name="sonar.core.coveragePlugin" value="jacoco" />
<property name="sonar.junit.reportsPath" value="${build.dir}/test-report"/>
<property name="sonar.jacoco.reportPath" value="${build.dir}/jacoc.exec" />
<javac srcdir="${src}:${test}" destdir="${bin}" target="1.7" debug="on"
source="1.7" encoding="cp1252">
<classpath refid="compileclasspath" />
</javac>