0

We are using ant for our build process. We wanted to get the test coverage for our project. So we integrated jacoco with sonar to perform the test coverage. The test Coverage is displayed correctly but the Unit Test Statistics are not displayed at all.

After searching in various forums we saw that it might be related with the sonar.tests/sonar.binaries/sonar.junit.reportsPath configuration.

But even after making all these changes we are still not able to see the Unit Test Statistics in Sonar.

We are using,

Sonar Qube 4.5.2 Sonar Ant 2.2 Jacoco 0.7.2.201409121644

Please Assist.

-build.xml

<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" >
                <classpath path="${jacoco_path}/lib/jacocoant.jar" />
</taskdef>
<target name="testCoverage" depends = "triv.build.all" description="Run unit tests and code coverage reporting">

    <jacoco:coverage destfile="${CB_dirsrc}/reports/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant">
            <junit haltonfailure="no" fork="true" printsummary="true" failureproperty="junitsFailed" errorProperty="junitsFailed" forkmode ="once">
                <jvmarg value="-XX:MaxPermSize=512m"/>
                <jvmarg value="-Xmx1024m"/>
                <jvmarg value="-Xms1024m"/>

                <classpath>
                    <path refid="test.classpath"/>
                    <path refid="core.classpath"/>
                    <pathelement path="${test.classes.dir}/classes"/>

                </classpath>
                <!--<formatter type="plain" usefile="false" />-->
                <formatter type="xml"/>
                <batchtest fork="yes" todir="${CB_dirsrc}/reports/junit">
                    <fileset dir="${test.src.dir}">
                        <!--<include name="**/*Test*.java"/>-->
                        <include name="**/*BasicTests.java"/>
                        <!--<exclude name="**/*BasicTests.java"/>-->
                        <exclude name="**/*TICPTestHook.java"/>
                        <exclude name="**/*TRIVTestCase.java"/>
                        <exclude name="**/*TestContext.java"/>

                    </fileset>
                </batchtest>
            </junit >
        </jacoco:coverage>
    </target>

<target name="report" depends ="testCoverage">
<!--<target name="report">-->
    <!-- Step 3: Create coverage report -->
    <jacoco:report xmlns:jacoco="antlib:org.jacoco.ant">
        <!-- This task needs the collected execution data and ... -->
        <executiondata>
            <file file="${CB_dirsrc}/reports/jacoco.exec"/>
        </executiondata>
        <!-- the class files and optional source files ... -->
        <structure name="JaCoCo Ant MPS Test">
            <classfiles>
                <fileset dir="${test.classes.dir}/classes" >
                    <!--<include name="**/*Test*.class"/>-->
                    <include name="**/*BasicTests.class"/>
                    <!--<exclude name="**/*BasicTests.class"/>-->
                    <exclude name="**/*TICPTestHook.class"/>
                    <exclude name="**/*TRIVTestCase.class"/>
                    <exclude name="**/*TestContext.class"/>
                 </fileset>
            </classfiles><sourcefiles encoding="UTF-8">
                <fileset dir="${test.src.dir}">
                     <!--<include name="**/*Test*.java"/>-->
                     <include name="**/*BasicTests.java"/>
                     <!--<exclude name="**/*BasicTests.java"/>-->
                     <exclude name="**/*TICPTestHook.java"/>
                     <exclude name="**/*TRIVTestCase.java"/>
                     <exclude name="**/*TestContext.java"/>
                    </fileset>
            </sourcefiles>
        </structure>
        <!-- to produce reports in different formats. -->
        <html destdir="${CB_dirsrc}/reports/jacoco"/>
        <csv destfile="${CB_dirsrc}/reports/jacoco/report.csv"/>
        <xml destfile="${CB_dirsrc}/reports/jacoco/report.xml"/>
    </jacoco:report>
</target>

<!-- SONAR-->
    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
            <classpath path="${sonar_ant_path}/sonar-ant-task-2.2.jar" />
    </taskdef>

    <target name="analyse" depends="report,init-sonar, sonar-java" description="Perform clean,build,testCoverage and sonar" >
        <!--depends="triv.build.all,report,init-sonar, sonar-java"-->
            <echo message="This task will do job of executing triv.clean, triv.build.all,testCoverage, init-sonar, sonar-java"/>
    </target>


<target name="init-sonar">
        <delete dir="${CB_dirsrc}/build/.sonar" />
      <!-- MYSQL SONAR DB -->
        <property name="sonar.jdbc.url"             value="${CB_sonar_db_url_value}" />
        <!--  <property name="${CB_sonar_db_driverClassName}" value="${CB_sonar_db_driverClassName_value}" /> -->
        <property name="sonar.jdbc.username"        value="${CB_sonar_db_username_value}" />
        <property name="sonar.jdbc.password"           value="${CB_sonar_db_password_value}" />
      <!-- SONAR SERVER HOST -->
        <property name="sonar.host.url"                     value="${CB_sonar_host_url}" />
      <!-- SONAR PROJECT NAME -->  
        <property name="sonar.projectName"              value="${CB_prd_longname}" />
        <property name="sonar.projectKey"               value="${CB_sonar_softwareId}" />
        <property name="sonar.projectVersion"               value="${CB_sonar_project_version}" />
        <property name="sonar.sources"               value="${CB_sonar_sources}" />
        <property name="sonar.tests"               value="${test.src.dir}" />
        <property name="sonar.verbose"               value="true" />
        <property name="sonar.dynamicAnalysis"               value="reuseReports" />
        <property name="sonar.junit.reportsPath"               value="${CB_dirsrc}/reports/junit" />
        <property name="sonar.surefire.reportsPath"               value="${CB_dirsrc}/reports/junit" />
        <property name="sonar.java.coveragePlugin"               value="jacoco" />
        <!--<property name="sonar.java.codeCoveragePlugin"               value="jacoco" />-->
        <property name="reports.dir"               value="${CB_dirsrc}/reports" />
        <property name="sonar.jacoco.reportPath"               value="${CB_dirsrc}/reports/jacoco.exec" />
        <property name="sonar.binaries"               value="target/classes" />
        <property name="sonar.sourceEncoding" value="UTF-8" />
        <property name="sonar.javascript.jstestdriver.reportsPath" value="${CB_dirsrc}/reports/junit" />

        <property name="jpos.sonar.projectBaseDir"               value="jpos/jpos" />
        <property name="jpos.sonar.projectName" value="jpos" />
        <property name="jpos.sonar.binaries" value="" />
        <property name="audit.sonar.projectName" value="audit" />
        <property name="callback.client.sonar.projectName" value="callback client" />
        <property name="callback.server.sonar.projectName" value="callback server" />
        <property name="consumerapp.sonar.projectName" value="consumerapp" />
        <property name="core.sonar.projectName" value="core" />
        <property name="external.sonar.projectName" value="external" />
        <property name="facade.sonar.projectName" value="facade" />
        <property name="facade.bank.sonar.projectName" value="facade bank" />
        <property name="facade.citi.sonar.projectName" value="facade citi" />
        <property name="facade.ssp.sonar.projectName" value="facade ssp" />
        <property name="facade.switch.sonar.projectName" value="facade switch" />
        <property name="facade.web.sonar.projectName" value="facade web" />
        <property name="openapi.sonar.projectName" value="openapi" />
        <property name="product.sonar.projectName" value="product" />
        <property name="services.sonar.projectName" value="services" />
        <property name="simulator.incoming.sonar.projectName" value="simulator incoming" />
        <property name="simulator.incoming.sonar.binaries" value="" />
        <property name="simulator.outgoing.sonar.projectName" value="simulator outgoing" />
        <property name="simulator.outgoing.sonar.binaries" value="" />
        <property name="svmas.sonar.projectName" value="svams" />
        <property name="test.sonar.projectName" value="test" />
        <property name="test.sonar.binaries" value="target/classes" />
        <property name="ui.sonar.projectName" value="ui" />
        <property name="ui.csc.sonar.projectName" value="ui csc" />
        <property name="ui.msc.sonar.projectName" value="ui msc" />
        <property name="ui.occ.sonar.projectName" value="ui occ" />
        <property name="ui.purchase.sonar.projectName" value="ui purchase" />
        <property name="util.sonar.projectName" value="util" />
        <property name="sonar.my.property" value="value" />
</target>

<target name="sonar-java">
        <property name="sonar.modules"                                    value="${CB_sonar_java_modules_list}" />
        <property name="sonar.language"                                   value="java" />
        <property name="sonar.branch"                                        value="Java" />
        <!--<property name="sonar.profile"                                         value="${CB_sonar_java_profile}" />--> 
        <property name="sonar.libraries"                                     value="${CB_sonar_libraries_list}" />
        <!-- <sonar:sonar key="${CB_sonar_softwareId}"  version="${CB_prd_shortversion}" xmlns:sonar="antlib:org.sonar.ant"/>-->  
        <sonar:sonar xmlns:sonar="antlib:org.sonar.ant"/>
</target>
  • Are you trying to get coverage of the tests code or the main source code. Test code coverage is always 100%. – AKS Jan 30 '15 at 22:15
  • I am getting the test coverage fine. The problem is the Unit Test Success/Failure Statistics is not reported. After reviewing multiple articles i saw that it might be related to surefire but not sure how to configure it with the sonar properties. – Prajwal Shetty Jan 31 '15 at 17:54
  • sonar.junit.reportsPath=... and sonar.surefire.reportsPath=... and it depends which version of sonar-runner / SonarQube you have. i.e. you might have to try, sonar.java.junit.reportsPath=... see if that works. To verify if your test results data (bunch of .xml / binary test files are correct), first see if Jenkins's (JUnit Publish plugin) can successfully publish that data (success/failures of tests) as a POST BUILD ACTION in a Jenkins job's dashboard. – AKS Feb 02 '15 at 17:00
  • Hi Arun, thanks for your prompt response. I tried using the sonar.java.junit.reportsPath and sonar.java.surefire.reportsPath but the result is the same. I still cannot see the Unit Test Success/failure statistics. In the directory dedicated to the junit test reports, i can see the xml files respective to each test class and the jacoco.exec is also updated with the results from these xml's. I am currently not permitted to use jenkins, hence cannot try the part you mentioned. Any other options to try ? – Prajwal Shetty Feb 06 '15 at 16:45
  • I assume you also tried sonar.surefire.reportsPath as well, right? If the .xml files are valid, then you can have someone in your company (who has access to Jenkins to create a dummy job which will not do anything other than a simple copy/paste of your tests results folder/files in that jobs's workspace and in the post build action, Publish JUnit test, that's it). BTW, install Jenkins on your local machine or a Linux machine and creating a job with what I said above, won't take more than 5-6 minutes for a naive user (time to learn Jenkins). – AKS Feb 06 '15 at 17:03
  • One other think if you can do.. zip whole test results contents and upload here. Someone might help you in showing how it looks like when Published in Jenkins. – AKS Feb 06 '15 at 17:03
  • Hi Arun, i installed jenkins locally and created the dummy job as you had suggested. The Test results are published properly in jenkins. – Prajwal Shetty Feb 18 '15 at 03:09
  • I had also tried using sonar.surefire.reportsPath and tried sonar.java.surefire.reportsPath but still no luck ... – Prajwal Shetty Feb 18 '15 at 03:15
  • are you using reuse reports property in sonar, try using it and make sure sonar.source and sonar.test(s) properties are setup correctly while doing the analysis part. – AKS Mar 04 '15 at 15:57
  • Hi Arun, If you are referring to the "sonar.dynamicAnalysis" property, yes i have used the "reuseReports" option. I will check again for the sonar.source and sonar.test properties. Thanks! – Prajwal Shetty Mar 05 '15 at 15:26
  • I have added the directory structure in a file avaiable at [link](http://wikisend.com/download/183382/directoryStructure.txt) – Prajwal Shetty Mar 09 '15 at 22:59
  • Any other suggestions anyone ? – Prajwal Shetty Jul 08 '15 at 14:33

0 Answers0