blob: 7bed3a5d54c93021a08a8b2333ca0e13d6b10cfe [file] [log] [blame]
Piotr Gurgulb0b67262009-09-01 21:58:52 -07001<?xml version="1.0" encoding="UTF-8"?>
2<project name="android_test_rules" default="run-tests">
3
4 <import file="android_rules.xml" />
5
Piotr Gurgulb0b67262009-09-01 21:58:52 -07006 <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
Piotr Gurgule9e8f8c2009-09-14 20:42:13 -07007 <property name="instrumentation.dir" value="instrumented" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -07008 <property name="instrumentation.absolute.dir" location="${instrumentation.dir}" />
9
10 <property name="test.runner" value="android.test.InstrumentationTestRunner" />
11 <property name="application.package.to.instrument" value="${application.package}.tests" />
12
Piotr Gurgulb0b67262009-09-01 21:58:52 -070013 <!-- TODO: make it more configurable in the next CL's - now it is default for auto-generated
14 project -->
15 <property name="emma.dump.file" value="/data/data/${application.package}/files/coverage.ec" />
16
Piotr Gurgulb0b67262009-09-01 21:58:52 -070017 <macrodef name="run-tests-helper">
18 <attribute name="emma.enabled" default="false" />
Piotr Gurgul47d7bdb2009-09-16 13:29:07 -070019 <element name="extra-instrument-args" optional="yes" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -070020 <sequential>
21 <echo>Running tests ...</echo>
22 <exec executable="${adb}" failonerror="true">
23 <arg value="shell" />
Piotr Gurgul47d7bdb2009-09-16 13:29:07 -070024 <arg value="am" />
25 <arg value="instrument" />
26 <arg value="-w" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -070027 <arg value="-e" />
28 <arg value="coverage" />
Piotr Gurgul47d7bdb2009-09-16 13:29:07 -070029 <arg value="@{emma.enabled}" />
30 <extra-instrument-args />
31 <arg value="${application.package.to.instrument}/${test.runner}" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -070032 </exec>
33 </sequential>
34 </macrodef>
35
Piotr Gurgule9e8f8c2009-09-14 20:42:13 -070036 <!-- Invoking this target sets the value of extensible.classpath, which is being added to javac
37 classpath in target 'compile' (android_rules.xml) -->
38 <target name="-set-coverage-classpath">
39 <property name="extensible.classpath"
40 location="${instrumentation.absolute.dir}/classes" />
41 </target>
42
43 <!-- Invoking this target sets the value of extensible.classpath, which is being added to javac
44 classpath in target 'compile' (android_rules.xml) -->
45 <target name="-set-run-tests-classpath">
46 <property name="extensible.classpath"
47 location="${tested.project.absolute.dir}/bin/classes" />
48 </target>
49
Piotr Gurgulb0b67262009-09-01 21:58:52 -070050 <!-- Ensures that tested project is installed on the device before we run the tests.
51 Used for ordinary tests, without coverage measurement -->
52 <target name="-install-tested-project">
53 <subant target="install">
54 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
55 </subant>
56 </target>
57
Piotr Gurgule9e8f8c2009-09-14 20:42:13 -070058 <target name="run-tests" depends="-set-run-tests-classpath, -install-tested-project, install"
Piotr Gurgulb0b67262009-09-01 21:58:52 -070059 description="Runs tests from the package defined in test.package property">
60 <run-tests-helper />
61 </target>
62
Piotr Gurgule9e8f8c2009-09-14 20:42:13 -070063 <target name="-install-instrumented">
64 <subant target="-install-with-emma">
65 <property name="out.absolute.dir" value="${instrumentation.absolute.dir}" />
66 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
67 </subant>
68 </target>
69
70 <target name="coverage" depends="-set-coverage-classpath, -install-instrumented, install"
71 description="Runs the tests against the instrumented code and generates
72 code coverage report">
Piotr Gurgul47d7bdb2009-09-16 13:29:07 -070073 <run-tests-helper emma.enabled="true">
74 <extra-instrument-args>
75 <arg value="-e" />
76 <arg value="coverageFile" />
77 <arg value="${emma.dump.file}" />
78 </extra-instrument-args>
79 </run-tests-helper>
Piotr Gurgulb0b67262009-09-01 21:58:52 -070080 <echo>Downloading coverage file into project directory...</echo>
81 <exec executable="${adb}" failonerror="true">
82 <arg value="pull" />
83 <arg value="${emma.dump.file}" />
84 <arg value="coverage.ec" />
85 </exec>
86 <echo>Extracting coverage report...</echo>
87 <emma>
88 <report sourcepath="${tested.project.absolute.dir}/${source.dir}"
89 verbosity="verbose">
90 <!-- TODO: report.dir or something like should be introduced if necessary -->
91 <infileset dir=".">
92 <include name="coverage.ec" />
93 <include name="coverage.em" />
94 </infileset>
95 <!-- TODO: reports in other, indicated by user formats -->
96 <html outfile="coverage.html" />
97 </report>
98 </emma>
Piotr Gurgul73b45f82009-09-16 10:43:19 -070099 <echo>Cleaning up temporary files...</echo>
100 <delete dir="${instrumentation.absolute.dir}" />
101 <delete file="coverage.ec" />
102 <delete file="coverage.em" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -0700103 </target>
104
105</project>