我对ANT脚本很新。我正在使用一个Android应用程序,我已经创建了相应的Junit android测试应用程序。现在我在我的测试项目的build.xml文件中有以下内容
<property name="src.dir" location="src" />
<property name="test.dir" location="tests" />
<property name="build.dir" location="bin" />
<property name="build.test.dir" location="bin/tests" />
<!-- Variables used for JUnit testin -->
<property name="test.report.dir" location="testreport" />
<!-- Define the classpath which includes the junit.jar and the classes after compiling-->
<path id="junit.class.path">
<pathelement location="libs/junit.jar" />
<pathelement location="lib/hamcrest-core-1.3.jar" />
<pathelement location="${build.dir}" />
</path>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${test.report.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.test.dir}" />
<mkdir dir="${test.report.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<echo>compile:clean, makedir</echo>
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath refid="junit.class.path" />
</javac>
<javac srcdir="${test.dir}" destdir="${build.test.dir}">
<classpath refid="junit.class.path" />
</javac>
</target>
<!-- Run the JUnit Tests -->
<!-- Output is XML, could also be plain-->
<target name="junit" depends="compile">
<echo>junit: compile</echo>
<junit printsummary="on" fork="true" haltonfailure="yes">
<classpath refid="junit.class.path" />
<classpath>
<pathelement location="${build.test.dir}"/>
</classpath>
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<fileset dir="${test.dir}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
<target name="main" depends="compile, junit">
<description>Main target</description>
</target>
当我按right click on build.xml->run as ant
运行上述代码时,我能够执行Junit测试脚本,但测试用例结果是alwasys错误或失败。我想,我需要在设备上执行这些测试脚本。如何在设备上执行这些测试脚本,同时我还需要获取代码覆盖率报告。请帮帮我。