1
votes

I want to see test coverage reports in my SonarQube 3.2.1., but see nothing and have the following error in my build:

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?

I execute Jacoco Ant report Task:

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

Jacoco version is 0.5.10.201208310627 (used by SonarQube 3.2.1) Under Jenkins, I'm invoking a standalone sonar analysis with the following conf:

# required metadata
sonar.projectKey=foo.bar
sonar.projectName=baz
sonar.projectVersion=1.0
sonar.verbose=true

# path to source directories (required)
sources=\
42-SSW/log4jAppender/src,\
42-SSW/webservicesCommun/src,\
42-SSW/webservicesMetier/src,\
...

# path to test source directories (optional)
tests=\
42-SSW/log4jAppender/test,\
42-SSW/webservicesCommun/test,\
42-SSW/webservicesMetier/test,\
...

# path to project binaries (optional), for example directory of Java bytecode
binaries=\
42-SSW/log4jAppender/build/jar,\
42-SSW/webservicesCommun/build/jar,\
42-SSW/webservicesMetier/build/jar,\
...

# optional comma-separated list of paths to libraries. Only path to JAR file and path to directory of classes are supported.
libraries=\
40-WAS/wsa/lib/servlet-api.jar,\
40-WAS/wsa/lib/axis.jar,\
...

# Uncomment those lines if some features of java 5 or java 6 like annotations, enum, ...
# are used in the source code to be analysed
sonar.java.source=1.5
sonar.java.target=1.5
sonar.sourceEncoding=UTF-8
sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=42-SSW/build/tuReport
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=42-SSW/build/codeCoverageReport/jacoco.exec

Any ideas ?

2
Did you have a look at our sample project to compare yours? => github.com/SonarSource/sonar-examples/tree/master/projects/… This could help you. - Fabrice - SonarSource Team
Yes. I don't use the Sonar Ant task, as Jenkins provides it for me. The only "big" difference I see is that my compiled ".class" have differents locations between TU classes and tested classes. I'll check that - Tusc

2 Answers

0
votes

Faced the same issue. By making below changes, I was able to get the coverage in sonar.[Note: In my case its build.xml]

<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" />

Include debug info in "compile" target.

<javac srcdir="${src}:${test}" destdir="${bin}" target="1.7" debug="on" 
source="1.7" encoding="cp1252">
<classpath refid="compileclasspath" />
</javac>
-2
votes

In your error log it sais:

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?

Looking at your ant script it seems you compile your test-sources with debug information. Do you compile the sources the test are covering with debug-information as well?

As it appears to be a jacoco related problem, I would also point you to jacoco-FAQ: http://www.eclemma.org/jacoco/trunk/doc/faq.html