目前我正在通过命令行运行测试工具:
adb shell am instrument -w com.blah.blah/android.test.InstrumentationTestRunner
有没有一种方法可以在Eclipse中运行它们(并自动安装应用程序)?function adbtest() {
adb shell am instrument -w -e class blah.package.$1 blah.package.test/android.test.InstrumentationTestRunner;
}
这样当我想要测试 blah.package.FooTest 时,我只需要记得输入以下内容:
james@trex:~$ adbtest FooTest
<!-- Compile this project's .java files into .class files. -->
<target name="compile" depends="dirs, resource-src, aidl">
<javac encoding="ascii" target="1.5" debug="true" extdirs=""
srcdir="src/:../src"
destdir="${outdir-classes}"
bootclasspath="${android-jar}">
<classpath>
<fileset dir="${external-libs}" includes="*.jar"/>
<fileset file="${junit-path}"/>
</classpath>
</javac>
</target>
<!-- Convert this project's .class files into .dex files. -->
<target name="dex" depends="compile">
<echo>Converting compiled files and external libraries into ${outdir}/${dex-file}...</echo>
<apply executable="${dx}" failonerror="true" parallel="true">
<arg value="--dex" />
<arg value="--output=${intermediate-dex-ospath}" />
<arg path="${outdir-classes-ospath}" />
<fileset dir="${external-libs}" includes="*.jar"/>
<fileset file="${junit-path}"/>
</apply>
</target>
<!-- Package the application and sign it with a debug key.
This is the default target when building. It is used for debug. -->
<target name="debug" depends="dex, package-res">
<echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo>
<exec executable="${apk-builder}" failonerror="true">
<arg value="${out-debug-package-ospath}" />
<arg value="-z" />
<arg value="${resources-package-ospath}" />
<arg value="-f" />
<arg value="${intermediate-dex-ospath}" />
<arg value="-rf" />
<arg value="${srcdir-ospath}" />
<arg value="-rj" />
<arg value="${external-libs-ospath}" />
<arg value="-rj" />
<arg value="${junit-path}" />
<arg value="-nf" />
<arg value="${native-libs-ospath}" />
</exec>
</target>
<target name="tests" depends="reinstall">
<echo>Building and installing tests..</echo>
<exec executable="ant" failonerror="true">
<arg value="-f" />
<arg value="tests/build.xml" />
<arg value="reinstall"/>
</exec>
<mkdir dir="${log-dir}" />
<exec executable="${adb}">
<arg value="shell" />
<arg value="am" />
<arg value="instrument" />
<arg value="-w" />
<arg value="-e" />
<arg value="class" />
<arg value="org.yourproject.AllTests" />
<arg value="org.yourproject.tests/android.test.InstrumentationTestRunner" />
</exec>
</target>
一旦所有设置都完成,启动模拟器并运行“ant tests”。这将在一个命令中构建、部署和执行您的测试。