非源代码类包含在emma xml覆盖率报告中

时间:2012-07-27 09:23:24

标签: android code-coverage emma

我正在使用Robotium在Android模拟器上运行UI测试并尝试使用emma进行覆盖。 xml覆盖率报告已成功创建。但我发现覆盖率报告中有一些类不是真实代码的一部分。如。。

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

我们在CalculatorData中根本没有名为Message的内部类。它看起来与内部类覆盖数据相同,因此我无法使用emma过滤器过滤它们。 有谁知道如何在覆盖率报告中删除这些数据?

这是我的相关蚂蚁脚本。

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

1 个答案:

答案 0 :(得分:1)

看起来你的Message课程中可能有一个名为CalculatorData的枚举。这会占到它吗?

相关问题