qc0530 - 2012-07-30

I am using Robotium to run UI test on Android Emulator and try to get coverage with emma. The xml coverage report is created successfully. But I found there are some classes in coverage report which are not parts of the real code. Such as.

<class name="CalculatorData$Message">
        <coverage type="class, %" value="0%   (0/1)"/>
        <coverage type="method, %" value="0%   (0/5)"/>
        <coverage type="block, %" value="0%   (0/43)"/>
        <coverage type="line, %" value="0%   (0/3)"/>

        <method name="&lt;static initializer&gt;">
          <coverage type="method, %" value="0%   (0/1)"/>
          <coverage type="block, %" value="0%   (0/24)"/>
          <coverage type="line, %" value="0%   (0/3)"/>
        </method>
        <method name="CalculatorData$Message (String, int): void">
          <coverage type="method, %" value="0%   (0/1)"/>
          <coverage type="block, %" value="0%   (0/5)"/>
          <coverage type="line, %" value="0%   (0/1)"/>
        </method>
        <method name="CalculatorData$Message (String, int, CalculatorData$1): void">
          <coverage type="method, %" value="0%   (0/1)"/>
          <coverage type="block, %" value="0%   (0/5)"/>
          <coverage type="line, %" value="0%   (0/1)"/>
        </method>
        <method name="valueOf (String): CalculatorData$Message">
          <coverage type="method, %" value="0%   (0/1)"/>
          <coverage type="block, %" value="0%   (0/5)"/>
          <coverage type="line, %" value="0%   (0/1)"/>
        </method>
        <method name="values (): CalculatorData$Message ">
          <coverage type="method, %" value="0%   (0/1)"/>
          <coverage type="block, %" value="0%   (0/4)"/>
          <coverage type="line, %" value="0%   (0/1)"/>
        </method>
      </class>
We don't have internal class named Message inside CalculatorData at all. It looks the same as the internal class coverage data so i can't filter them with emma filter. Does anyone know how to get rid of these data in the coverage report?

Here is my related ant script.

<property name="emma.filter" value="-com.example.coverage.R, -com.example.coverage.R$*, -com.example.coverage.BuildConfig" />  
<property name="emma.default.filter" value="com.example.coverage.R, com.example.coverage.R$*, com.example.coverage.BuildConfig" /> 
<import file="${sdk.dir}/tools/ant/build.xml" />

<!- use com.zutubi.android.junitreport.JUnitReportTestRunner for getting junit report ->
<property name="test.runner.with.report" value="com.zutubi.android.junitreport.JUnitReportTestRunner" />

<!- refer to run-tests-helper in ${sdk.dir}/tools/ant/build.xml ->
<macrodef name="run-tests-helper-with-report">
    <attribute name="emma.enabled" default="false" />
    <element name="extra-instrument-args" optional="yes" />
    <sequential>
        <echo>Running tests …</echo>
        <exec executable="${adb}" failonerror="true">
            <arg line="${adb.device.arg}" />
            <arg value="shell" />
            <arg value="am" />
            <arg value="instrument" />
            <arg value="-w" />
            <arg value="-e" />
            <arg value="coverage" />
            <arg value="@{emma.enabled}" />
            <extra-instrument-args />
            <arg value="${manifest.package}/${test.runner.with.report}" />
        </exec>
    </sequential>
</macrodef>

<!- customize system test target using run-tests-helper-with-report for getting junit report ->
<target name="test-with-report" depends="-test-project-check" description="Runs tests from the package defined in test.package property">

    <property name="tested.project.absolute.dir" location="${tested.project.dir}" />

    <!- Application package of the tested project extracted from its manifest file ->
    <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml" expression="/manifest/@package" output="tested.manifest.package" />
    <xpath input="AndroidManifest.xml" expression="/manifest/@package" output="manifest.package" />

    <property name="emma.dump.file" value="/data/data/${tested.manifest.package}/coverage.ec" />
    <property name="reports.dir" value="${out.dir}/reports" />
    <property name="files.dir" value="/data/data/${manifest.package}/files" />

    <echo>Cleaning up previous test reports…</echo>
    <delete dir="${reports.dir}" />
    <delete dir="${basedir}/coverage" />

    <if condition="${emma.enabled}">
        <then>
            <echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo>
            <run-tests-helper-with-report emma.enabled="true">
                <extra-instrument-args>
                    <arg value="-e" />
                    <arg value="coverageFile" />
                    <arg value="${emma.dump.file}" />
                </extra-instrument-args>
            </run-tests-helper-with-report>
            <echo>Downloading coverage file into project directory…</echo>
            <exec executable="${adb}" failonerror="true">
                <arg line="${adb.device.arg}" />
                <arg value="pull" />
                <arg value="${emma.dump.file}" />
                <arg value="coverage.ec" />
            </exec>
            <echo>Extracting coverage report…</echo>
            <emma>
                <report sourcepath="${tested.project.absolute.dir}/${source.dir}" verbosity="${verbosity}">
                    <!- TODO: report.dir or something like should be introduced if necessary ->
                    <infileset dir=".">
                        <include name="coverage.ec" />
                        <include name="coverage.em" />
                    </infileset>
                    <!- TODO: reports in other, indicated by user formats ->
                    <html outfile="ui-test-coverage.html" encoding="UTF-8"/>
                    <xml outfile="ui-test-coverage.xml" encoding="UTF-8"/>
                </report>
            </emma>
            <echo>Saving the report file in ${basedir}/coverage/coverage.html</echo>
        </then>
        <else>
            <run-tests-helper-with-report />
        </else>
    </if>

    <echo>Downloading XML test report…</echo>
    <mkdir dir="${reports.dir}" />
    <exec executable="${adb}" failonerror="true">
        <arg line="${adb.device.arg}" />
        <arg value="pull" />
        <arg value="/data/data/${tested.manifest.package}/files/junit-report.xml" />
        <arg value="${reports.dir}/ui-test-report.xml" />
    </exec>
</target>