blob: 15215800ccef2ad9e23d50a103ba9051067b7b4b [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<project name="android_test_rules" default="run-tests">
<import file="android_rules.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" />
<property name="application.package.to.instrument" value="${application.package}.tests" />
<!-- 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/${application.package}/files/coverage.ec" />
<macrodef name="run-tests-helper">
<attribute name="emma.enabled" default="false" />
<sequential>
<echo>Running tests ...</echo>
<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}" />
<arg value="${application.package.to.instrument}/${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>
<!-- 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-run-tests-classpath">
<property name="extensible.classpath"
location="${tested.project.absolute.dir}/bin/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">
<subant target="install">
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
</subant>
</target>
<target name="run-tests" depends="-set-run-tests-classpath, -install-tested-project, install"
description="Runs tests from the package defined in test.package property">
<run-tests-helper />
</target>
<target name="-install-instrumented">
<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" />
<echo>Downloading coverage file into project directory...</echo>
<exec executable="${adb}" failonerror="true">
<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="verbose">
<!-- 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>
</target>
</project>