如何在android中使用EMMA代码覆盖

时间:2021-09-09 00:24:23

I'm new to EMMA, I don't know how to use this for android system. Can anyone please give a sample for using this with android. Thanks a lot.

我是EMMA的新手,我不知道如何在Android系统中使用它。任何人都可以提供一个使用Android的示例。非常感谢。

3 个解决方案

#1


9  

I've only been able to get emma working using ant. If you've got an ant build set up then you can run:

我只能让艾玛使用蚂蚁工作。如果您已经设置了ant构建,那么您可以运行:

ant emma debug install
ant emma debug install test

The first is run in your project directory, the second from your test directory. See the docs for more details: http://developer.android.com/guide/developing/building/building-cmdline.html

第一个在您的项目目录中运行,第二个在您的测试目录中运行。有关详细信息,请参阅文档:http://developer.android.com/guide/developing/building/building-cmdline.html

If you don't have an ant build.xml file already you can see how to generate one from your current project here: http://developer.android.com/guide/developing/projects/projects-cmdline.html

如果您还没有ant build.xml文件,可以在此处查看如何从当前项目生成一个文件:http://developer.android.com/guide/developing/projects/projects-cmdline.html

The sad part is this will only work on the emulator or a rooted device. This is because the coverage file gets generated in a folder that requires root. I also needed to modify the android-sdk/tools/ant/build.xml file to copy the file on my rooted device elsewhere so I could pull it off. I modified the emma block of the xml to be the following:

可悲的是,这只适用于模拟器或有根设备。这是因为覆盖文件是在需要root的文件夹中生成的。我还需要修改android-sdk / tools / ant / build.xml文件,将我的root设备上的文件复制到其他地方,这样我就可以将其删除。我修改了xml的emma块,如下所示:

    <if condition="${emma.enabled}">
        <then>
            <echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo>
            <run-tests-helper emma.enabled="true">
                <extra-instrument-args>
                    <arg value="-e" />
                       <arg value="coverageFile" />
                       <arg value="${emma.dump.file}" />
                </extra-instrument-args>
            </run-tests-helper>
            <echo>Copying coverage to readable directory...</echo>
            <exec executable="${adb}" failonerror="true">
                <arg line="${adb.device.arg}" />
                <arg value="shell" />
                <arg value="echo cp ${emma.dump.file} /sdcard/coverage.ec | su" />
            </exec>
            <echo>Downloading coverage file into project directory...</echo>
            <exec executable="${adb}" failonerror="true">
                <arg line="${adb.device.arg}" />
                <arg value="pull" />
                <arg value="/sdcard/coverage.ec" />
                <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="coverage.html" />
               </report>
            </emma>
            <echo>Cleaning up temporary files...</echo>
            <delete file="coverage.ec" />
            <delete file="coverage.em" />
            <echo>Saving the report file in ${basedir}/coverage/coverage.html</echo>
        </then>
        <else>
            <run-tests-helper />
        </else>
    </if>

#2


8  

Apparently EMMA isn't supported for the SDK Yet. It's only supported for Apps and Tests that are part of the source tree. Which seems weird because they don't mention this in the dev-guide where they tell you about the EMMA instrumentation options. http://developer.android.com/guide/developing/testing/testing_otheride.html#AMOptionsSyntax

显然,SDK尚不支持EMMA。它仅支持作为源树的一部分的应用和测试。这看起来很奇怪,因为他们没有在开发指南中提到这一点,他们告诉你有关EMMA仪表选项的信息。 http://developer.android.com/guide/developing/testing/testing_otheride.html#AMOptionsSyntax

You can read the response from this guy (who appears to be on the dev team? I dunno) http://groups.google.com/group/android-developers/msg/a542afd318832371

你可以阅读这个人的回复(他似乎是开发团队的成员吗?我不知道)http://groups.google.com/group/android-developers/msg/a542afd318832371

If you want to download and build the Android Source it sounds feasible to get EMMA working for your own App. However, it sounds kind of tricky and possibly a little unstable. See the full thread for more info: http://groups.google.com/group/android-developers/browse_thread/thread/43cf8a8ca5662f85/9b68eec3e7b625f3?lnk=gst&q=Emma#

如果您想下载并构建Android源,那么让EMMA为您自己的应用程序工作听起来是可行的。然而,这听起来有点棘手,可能有点不稳定。有关详细信息,请参阅完整主题:http://groups.google.com/group/android-developers/browse_thread/thread/43cf8a8ca5662f85/9b68eec3e7b625f3?lnk=gst&q=Emma#

#3


1  

If you are using maven for your project is fairly simple with rooted devices check this wiki :

如果你使用maven为你的项目相当简单的root设备检查这个维基:

http://code.google.com/p/maven-android-plugin/wiki/EmmaMaven

it was easy to implement the solution apart the report generation but if you check the comments of the wiki you will find the solution

除了生成报告之外,很容易实现解决方案,但如果您查看维基的评论,您将找到解决方案

#1


9  

I've only been able to get emma working using ant. If you've got an ant build set up then you can run:

我只能让艾玛使用蚂蚁工作。如果您已经设置了ant构建,那么您可以运行:

ant emma debug install
ant emma debug install test

The first is run in your project directory, the second from your test directory. See the docs for more details: http://developer.android.com/guide/developing/building/building-cmdline.html

第一个在您的项目目录中运行,第二个在您的测试目录中运行。有关详细信息,请参阅文档:http://developer.android.com/guide/developing/building/building-cmdline.html

If you don't have an ant build.xml file already you can see how to generate one from your current project here: http://developer.android.com/guide/developing/projects/projects-cmdline.html

如果您还没有ant build.xml文件,可以在此处查看如何从当前项目生成一个文件:http://developer.android.com/guide/developing/projects/projects-cmdline.html

The sad part is this will only work on the emulator or a rooted device. This is because the coverage file gets generated in a folder that requires root. I also needed to modify the android-sdk/tools/ant/build.xml file to copy the file on my rooted device elsewhere so I could pull it off. I modified the emma block of the xml to be the following:

可悲的是,这只适用于模拟器或有根设备。这是因为覆盖文件是在需要root的文件夹中生成的。我还需要修改android-sdk / tools / ant / build.xml文件,将我的root设备上的文件复制到其他地方,这样我就可以将其删除。我修改了xml的emma块,如下所示:

    <if condition="${emma.enabled}">
        <then>
            <echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo>
            <run-tests-helper emma.enabled="true">
                <extra-instrument-args>
                    <arg value="-e" />
                       <arg value="coverageFile" />
                       <arg value="${emma.dump.file}" />
                </extra-instrument-args>
            </run-tests-helper>
            <echo>Copying coverage to readable directory...</echo>
            <exec executable="${adb}" failonerror="true">
                <arg line="${adb.device.arg}" />
                <arg value="shell" />
                <arg value="echo cp ${emma.dump.file} /sdcard/coverage.ec | su" />
            </exec>
            <echo>Downloading coverage file into project directory...</echo>
            <exec executable="${adb}" failonerror="true">
                <arg line="${adb.device.arg}" />
                <arg value="pull" />
                <arg value="/sdcard/coverage.ec" />
                <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="coverage.html" />
               </report>
            </emma>
            <echo>Cleaning up temporary files...</echo>
            <delete file="coverage.ec" />
            <delete file="coverage.em" />
            <echo>Saving the report file in ${basedir}/coverage/coverage.html</echo>
        </then>
        <else>
            <run-tests-helper />
        </else>
    </if>

#2


8  

Apparently EMMA isn't supported for the SDK Yet. It's only supported for Apps and Tests that are part of the source tree. Which seems weird because they don't mention this in the dev-guide where they tell you about the EMMA instrumentation options. http://developer.android.com/guide/developing/testing/testing_otheride.html#AMOptionsSyntax

显然,SDK尚不支持EMMA。它仅支持作为源树的一部分的应用和测试。这看起来很奇怪,因为他们没有在开发指南中提到这一点,他们告诉你有关EMMA仪表选项的信息。 http://developer.android.com/guide/developing/testing/testing_otheride.html#AMOptionsSyntax

You can read the response from this guy (who appears to be on the dev team? I dunno) http://groups.google.com/group/android-developers/msg/a542afd318832371

你可以阅读这个人的回复(他似乎是开发团队的成员吗?我不知道)http://groups.google.com/group/android-developers/msg/a542afd318832371

If you want to download and build the Android Source it sounds feasible to get EMMA working for your own App. However, it sounds kind of tricky and possibly a little unstable. See the full thread for more info: http://groups.google.com/group/android-developers/browse_thread/thread/43cf8a8ca5662f85/9b68eec3e7b625f3?lnk=gst&q=Emma#

如果您想下载并构建Android源,那么让EMMA为您自己的应用程序工作听起来是可行的。然而,这听起来有点棘手,可能有点不稳定。有关详细信息,请参阅完整主题:http://groups.google.com/group/android-developers/browse_thread/thread/43cf8a8ca5662f85/9b68eec3e7b625f3?lnk=gst&q=Emma#

#3


1  

If you are using maven for your project is fairly simple with rooted devices check this wiki :

如果你使用maven为你的项目相当简单的root设备检查这个维基:

http://code.google.com/p/maven-android-plugin/wiki/EmmaMaven

it was easy to implement the solution apart the report generation but if you check the comments of the wiki you will find the solution

除了生成报告之外,很容易实现解决方案,但如果您查看维基的评论,您将找到解决方案