开发者

How to use EMMA code coverage in android

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 wi开发者_开发技巧th android. Thanks a lot.


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

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

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:

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


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

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

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#


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜