alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Android example source code file (ant_test_rules_r2.xml)

This example Android source code file (ant_test_rules_r2.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Android by Example" TM.

Java - Android tags/keywords

application, cl's, ensures, invoking, runs, todo, used, utf-8

The ant_test_rules_r2.xml Android example source code

<?xml version="1.0" encoding="UTF-8"?>
<project name="android_test_rules" default="run-tests">

    <import file="ant_rules_r2.xml" />

    <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
    <property name="instrumentation.dir" value="instrumented" />
    <property name="instrumentation.absolute.dir" location="${instrumentation.dir}" />

    <property name="test.runner" value="android.test.InstrumentationTestRunner" />
    <!-- Application package of the tested project extracted from its manifest file -->
    <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
                expression="/manifest/@package" output="tested.manifest.package" />

    <!-- TODO: make it more configurable in the next CL's - now it is default for auto-generated
         project -->
    <property name="emma.dump.file"
                  value="/data/data/${tested.manifest.package}/files/coverage.ec" />

    <macrodef name="run-tests-helper">
        <attribute name="emma.enabled" default="false" />
        <element name="extra-instrument-args" optional="yes" />
        <sequential>
            <echo>Running tests ...
            <exec executable="${adb}" failonerror="true">
                <arg value="shell" />
                <arg value="am" />
                   <arg value="instrument" />
                <arg value="-w" />
                <arg value="-e" />
                   <arg value="coverage" />
                   <arg value="@{emma.enabled}" />
                <extra-instrument-args />
                <arg value="${manifest.package}/${test.runner}" />
            </exec>
        </sequential>
    </macrodef>

    <!-- Invoking this target sets the value of extensible.classpath, which is being added to javac
         classpath in target 'compile' (android_rules.xml) -->
    <target name="-set-coverage-classpath">
        <property name="extensible.classpath"
                      location="${instrumentation.absolute.dir}/classes" />
    </target>

    <!-- Ensures that tested project is installed on the device before we run the tests.
         Used for ordinary tests, without coverage measurement -->
    <target name="-install-tested-project">
        <property name="do.not.compile.again" value="true" />
        <subant target="install">
            <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
        </subant>
    </target>

    <target name="run-tests" depends="-install-tested-project, install"
                description="Runs tests from the package defined in test.package property">
        <run-tests-helper />
    </target>

    <target name="-install-instrumented">
        <property name="do.not.compile.again" value="true" />
        <subant target="-install-with-emma">
            <property name="out.absolute.dir" value="${instrumentation.absolute.dir}" />
            <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
        </subant>
    </target>

    <target name="coverage" 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...
        <exec executable="${adb}" failonerror="true">
            <arg value="pull" />
            <arg value="${emma.dump.file}" />
            <arg value="coverage.ec" />
        </exec>
        <echo>Extracting coverage report...
        <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...
        <delete dir="${instrumentation.absolute.dir}" />
        <delete file="coverage.ec" />
        <delete file="coverage.em" />
        <echo>Saving the report file in ${basedir}/coverage/coverage.html
    </target>

</project>

Other Android examples (source code examples)

Here is a short list of links related to this Android ant_test_rules_r2.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.