10

Ant、Jacoco、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>

私のソナーターゲットは次のようになります。

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

誰かが私が欠けているものを知っていますか?

4

2 に答える 2

1

プロパティはsonar.testテスト クラスに設定する必要があります。Maven pomには次のものがあります。ANT の場合、同様のことを行います。

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

ちなみに、これで使用されている他のプロパティがいくつかあります。

  • ログインとパスワードを使用するのではなく、ソナー ユーザーを介して SONAR トークンを生成しました
  • JaCoCo カバレッジは、 を使用して個別に生成されてjacoco-maven-pluginおり、sonar.jacoco.reportPathはそのプラグインで使用されるプロパティです。

David Racodon の回答 ( https://stackoverflow.com/a/16645108/1019307 ) はかつては正しかったのですが、2014 年半ばに SonarQube はソナー実行の一部としてテストの実行を停止しました ( http://www.sonarqube.org/unit- test-execution-in-sonarqube/ )。したがって、テストソースを指すことが機能しなくなったのはなぜですか。

于 2016-06-17T21:33:23.457 に答える