即使显示测试覆盖率,也不会在声纳中显示单位测试统计数据

时间:2015-01-29 18:48:07

标签: ant junit sonarqube jacoco test-coverage

我们在构建过程中使用ant。我们希望获得项目的测试覆盖率。因此我们将jacoco与声纳集成以执行测试覆盖。 测试覆盖率正确显示,但单位测试统计数据根本不显示。

在各种论坛中搜索后,我们发现它可能与sonar.tests / sonar.binaries / sonar.junit.reportsPath配置有关。

但即使在进行了所有这些更改之后,我们仍然无法在Sonar中看到单元测试统计数据。

我们正在使用,

Sonar Qube 4.5.2 Sonar Ant 2.2 Jacoco 0.7.2.201409121644

请协助。

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

0 个答案:

没有答案