0

我正在使用 Robotium 在 Android Emulator 上运行 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>
4

1 回答 1

1

这些看起来你可能Message在你的CalculatorData类中调用了一个枚举。这能解释吗?

于 2012-12-18T09:37:44.903 回答