"No information about coverage per test." from Sonar with Jacoco Ant build

14,565

Solution 1

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.

David RACODON | SonarSource

Solution 2

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:

    <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 the sonar.jacoco.reportPath is a property used in that plugin.

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.

Share:
14,565
Paul Grenyer
Author by

Paul Grenyer

Husband, father, software consultant, author, testing and agile evangelist. I have been programming in one form or another for over 20 years and have been involved in building agile teams since 2007. After several years of C++ I am very happy developing with Java and C#. I have worked in industries as diverse as marking machinery, direct mail, mobile phones, insurance and Internet TV. I have been an ACCU member since 2001, a regular publications contributor, including the now well established Desert Island Books column, creator of the mentored developers and a committee member for most of that time. When I'm not programming or chasing my 3 children, I thoroughly enjoys science fiction, heavy metal and cycling. Specialties Robust software development in Java, C++ &amp; C#, Automated testing, build engineering and Continuous Integration.

Updated on July 20, 2022

Comments

  • Paul Grenyer
    Paul Grenyer almost 2 years

    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:

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

  • Adam Adamaszek
    Adam Adamaszek almost 11 years
    I confirm - in my case, this was set to test sources, whereas it should point to the compiled classes.
  • Paul Grenyer
    Paul Grenyer almost 11 years
    I've tried adding the sonar.tests property to point to both source code and byte code. Neither worked. I'm still stumped with this.
  • rozner
    rozner almost 11 years
    I have the same problem. I think this may be a bug with the Ant task as I had done this using Sonar Runner and it worked fine, but the same properties in Ant fail.
  • Ryan Walls
    Ryan Walls about 10 years
    Happens with gradle builds as well.
  • krems
    krems over 9 years
    Haven't you try adding this property: sonar.jacoco.itReportPath=target/jacoco-it.exec ?
  • Hubert Grzeskowiak
    Hubert Grzeskowiak over 7 years
    It's sonar.tests, not sonar.test Also: "Not compatible with Maven, which retrieves test from the default location for Java Maven projects." See docs.sonarqube.org/display/SONAR/Analysis+Parameters
  • HankCa
    HankCa over 7 years
    Ok that is one parameter wrong (although it did work for me). Although it isn't actually wrong but redundant. Is that a reason to downvote? A simple comment would have had me update my answer.
  • John Allison
    John Allison almost 4 years
    @AdamAdamaszek, you are wrong. As stated clearly in the Analysis Parameters section at the link above, the sonar.tests property should contain comma-separated paths to directories containing test source files.