testing – How to use EMMA code coverage in android-ThrowExceptions

Exception or error:

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.

How to solve:

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}">
            <echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo>
            <run-tests-helper emma.enabled="true">
                    <arg value="-e" />
                       <arg value="coverageFile" />
                       <arg value="${emma.dump.file}" />
            <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" />
            <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" />
            <echo>Extracting coverage report...</echo>
                <report sourcepath="${tested.project.absolute.dir}/${source.dir}"
                    <!-- TODO: report.dir or something like should be introduced if necessary -->
                    <infileset dir=".">
                        <include name="coverage.ec" />
                        <include name="coverage.em" />
                    <!-- TODO: reports in other, indicated by user formats -->
                    <html outfile="coverage.html" />
            <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>
            <run-tests-helper />


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.

You can read the response from this guy (who appears to be on the dev team? I dunno)

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:


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


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

Leave a Reply

Your email address will not be published. Required fields are marked *