a little madness

A man needs a little madness, or else he never dares cut the rope and be free -Nikos Kazantzakis


Android JUnit XML Reports: Multiple File Support

Due to popular demand, I’ve added support for multiple output files (one per test suite) to android-junit-report.

For simplicity and efficiency, android-junit-report does not produce files in the exact format used by the Ant JUnit task. In the 1.1 release there are two main differences:

  1. A single report file is produced containing all test suites.
  2. Redundant information, such as the number of cases, failures etc is not added using attributes on the testsuite tag.

It turns out the first of these restrictions caused multiple users issues with tools accustomed to handling a single report file per suite. So in the latest 1.2 release I have added a new multiFile option. When this option is enabled, android-junit-report produces a separate output file for each test suite. This does mean that to retrieve the results from the device you will need to pull a whole directory.

To enable this option from an Ant build, you can override the default run-tests target as follows:

<target name="run-tests" depends="-install-tested-project, install"
       description="Runs tests from the package defined in test.package property">
    <property name="reports.dir" value="${out.dir}/reports"/>
    <property name="files.dir" value="/data/data/${tested.manifest.package}/files"/>
    <echo>Cleaning up previous test reports…</echo>
    <delete dir="${reports.dir}"/>
    <exec executable="${adb}" failonerror="true">
        <arg line="${adb.device.arg}" />
        <arg value="shell" />
        <arg value="rm" />
        <arg value="${files.dir}/*" />
    <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}" />
        <arg value="-e" />
        <arg value="multiFile" />
        <arg value="true" />
        <arg value="${manifest.package}/${test.runner}" />
    <echo>Downloading XML test reports…</echo>
    <mkdir dir="${reports.dir}"/>
    <exec executable="${adb}" failonerror="true">
        <arg line="${adb.device.arg}"/>
        <arg value="pull" />
        <arg value="${files.dir}" />
        <arg value="${reports.dir}" />

You can learn more about android-junit-report and/or download the new release using the links below:

Liked this post? Share it!

3 Responses to “Android JUnit XML Reports: Multiple File Support”

  1. April 13th, 2011 at 5:50 am

    Bill says:

    Does this require root on a hardware device. I have been trying to get this to work but am not able to access the data directory.

    Is there a work around using another directory that has generic read/write access?

  2. April 15th, 2011 at 12:02 pm

    Jason says:

    Hi Bill,

    Some users have reported so. In the latest version (which you can get from GitHub) there is a new reportDir argument which you can use to customise the output directory. You may want to, e.g., write to the SD card instead.

  3. October 18th, 2011 at 10:17 pm

    everything about java says:

    everything about java…

    […]a little madness » Blog Archive » Android JUnit XML Reports: Multiple File Support[…]…

Leave a Reply