Recently we set up a Hudson continuous integration server at work. We are developing android apps and when I found out that Hudson had an Emma plugin I got excited. I found out about emma and android’s coverage reports. There was however one problem. Android’s <code>ant coverage</code> build will only output an html report. The hudson plugin requires an xml report.

To fix this I created a new build action in my build.xml. This is actually word for word what is in the coverage target with one minor change.

<target name="coverage-xml" depends="-set-coverage-classpath, -install-instrumented, install" description="Runs the tests against the instrumented code and generates code coverage report">
        <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>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 -->
                <xml outfile="coverage.xml" />
            </report>
        </emma>
        <echo>Cleaning up temporary files...</echo>
        <delete dir="${instrumentation.absolute.dir}" />
        <delete file="coverage.ec" />
        <delete file="coverage.em" />
        <echo>Saving the report file in ${basedir}/coverage/coverage.xml</echo>
    </target>

Here you can see the only real change to the target is this line:

<xml outfile="coverage.xml" />

as opposed to this

<html outfile="coverage.html" />

. Now we can output our coverage report to our workspace and feed it to the Hudson Emma plugin.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>