"没有关于每次测试覆盖率的信息." 来自Sonar与Jacoco Ant构建

Pau*_*yer 10 java ant junit jacoco sonarqube

我正在使用Ant,Jacoco和Sonar.当我运行我的构建时,Sonar告诉我"没有关于每次测试覆盖率的信息." 并且Sonar仪表板具有我的覆盖结果,但我无法深入查看它们以查看代码.但是,Jacoco生成的HTML报告确实包含深入到代码中.这是我的承保任务:

    <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>
Run Code Online (Sandbox Code Playgroud)

我的声纳目标看起来像这样:

<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>
Run Code Online (Sandbox Code Playgroud)

有谁知道我错过了什么?

小智 2

看起来您还没有设置“sonar.tests”属性来告诉 Sonar 在哪里可以找到单元测试的源代码。请参阅http://docs.sonarqube.org/display/SONAR/Analysis+Parameters

大卫·雷科登 | 声纳源

  • 我尝试添加 sonar.tests 属性以指向源代码和字节代码。两者都不起作用。我仍然对此感到困惑。 (5认同)
  • 我确认 - 就我而言,这被设置为测试源,而它应该指向已编译的类。 (2认同)