How to get Sonar to export test statistics?

I have the following Ant target set:

<target name='sonar'>
    <property name='sonar.sources' value='${src.dir}'/>
    <property name='sonar.tests' value='${test.src.dir}'/>
    <property name='sonar.binaries' value='build/classes'/>
    <path id='jars'>
        <fileset dir='${env.JAVA_HOME}/jre/lib' includes='*.jar'/>
        <fileset dir='build/lib/test' includes='*.jar'/>
    </path>
    <pathconvert property='sonar.libraries' refid='jars' pathsep=','/>

    <exec executable='p4' outputproperty='p4.P4CLIENT'>
        <arg value='set'/>
        <arg value='P4CLIENT'/>
    </exec>
    <propertyregex
            property='p4client'
            input='${p4.P4CLIENT}'
            regexp='P4CLIENT=([^ ]+) *.*'
            replace='\1'/>
    <propertyregex
            property='sonar.timestamp'
            input='${build.time}'
            regexp='_'
            replace='T'/>
    <sonar:sonar key='com.netflix:${module.name}' version='${p4client}@${sonar.timestamp}' xmlns:sonar='antlib:org.sonar.ant'/>

    <property name='sonar.dynamicAnalysis' value='reuseReports'/>
    <property name='sonar.emma.reportPath' value='${coverage.dir}'/>
</target>

When I run 'ant sonar' and display Sonar in my browser, I see the class information in the src directory, but nothing about the material in the test directory.

If I add $ {test.src.dir} to sonar.sources and do not specify sonar.tests, I see some information about the test classes, but Sonar still reports 0 Test Successes.

How to get it so that I can deploy each testing method and their statistics?

+5
source share
2 answers

The sonar.surefire.reportsPath property must be defined before defining a sonar target.

( ):

<property name='sonar.surefire.reportsPath' value='${test.dir}'/>

<property name='sonar.dynamicAnalysis' value='reuseReports'/>
<property name='sonar.emma.reportPath' value='${coverage.report.dir}'/>

<target name='sonar'>
    <property name='sonar.sources' value='${src.dir}'/>
    <property name='sonar.tests' value='${test.src.dir}'/>
    <property name='sonar.binaries' value='${build.dir}'/>
    <path id='jars'>
        <fileset dir='${env.JAVA_HOME}/jre/lib' includes='*.jar'/>
        <fileset dir='${ivy.lib.dir}/test' includes='*.jar'/>
    </path>
    <pathconvert property='sonar.libraries' refid='jars' pathsep=','/>

    <exec executable='p4' outputproperty='p4.P4CLIENT'>
        <arg value='set'/>
        <arg value='P4CLIENT'/>
    </exec>
    <propertyregex
            property='p4client'
            input='${p4.P4CLIENT}'
            regexp='P4CLIENT=([^ ]+) *.*'
            replace='\1'/>
    <propertyregex
            property='sonar.timestamp'
            input='${build.time}'
            regexp='_'
            replace='T'/>

    <sonar:sonar key='com.netflix:${module.name}' version='${p4client}@${sonar.timestamp}' xmlns:sonar='antlib:org.sonar.ant'/>
</target>
+2

, , , , Sonar, Emma Code. , Emma Sonar, (3.1.1). extensions/plugins Sonar .

build.xml:

<property name="sonar.core.codeCoveragePlugin" value="emma" />
<property name="sonar.emma.reportPath" value="${coverage.dir}" />

, , Sonar ant:

[sonar:sonar] 13:41:49.705 WARN        org.sonar.INFO - No coverage (*.ec) file found in /my/local/path
[sonar:sonar] 13:41:49.708 WARN        org.sonar.INFO - No metadata (*.em) file found in /my/local/path

, Sonar Emma .ec() .em(). , .emma, , , . ant, , Sonar Emma.

<target name="createEmmaFilesWithSonarNamingStandard" depends="defineAntContribTasks">
    <if>
        <available file="${coverage.dir}/metadata.emma" />
        <then>
            <copyfile src="${coverage.dir}/metadata.emma" dest="${coverage.dir}/metadata.em" />
        </then>
    </if>
    <if>
        <available file="${coverage.dir}/coverage.emma" />
        <then>
            <copyfile src="${coverage.dir}/coverage.emma" dest="${coverage.dir}/coverage.ec" />
        </then>
    </if>
</target>

:

org.sonar.api.utils.SonarException: java.io.IOException: cannot read [/my/local/path/build/coverage/metadata.em]: created by another EMMA version [2.0.5312]

, Sonar Emma 1.0.1 Emma 2.0.5312 Sonar Emma 1.1 1.2.x Emma 2.1.5320, Sonar Emma.

Emma 2.1.5320, emma.jar, emma_ant.jar ant lib. Sonar ant Sonar.

+6

All Articles