无法 运行 UIAutomator 在最新版本的 Android SDK 中进行测试
Cannot run UIAutomator tests in latest version of Android SDK
我已经升级到最新版本的 Android Studio (1.5) 和 SDK,现在我的 UIAutomator 测试, 运行 来自 ant,不再工作了(他们曾经工作过,直到 Android Studio 1.0.x)。
这是我用来 运行 测试的脚本:
@echo off
cls
set ANDROID_HOME=C:\Users\xxxx\AppData\Local\Android\sdk
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_65
cmd /c ..\..\..\..\..\..\..\..\thirdparty\ant\bin\ant build
if ERRORLEVEL 1 goto end
:run
cmd /c adb push ..\..\..\..\..\..\..\app\libs\uiautomator.jar /data/local/tmp
cmd /c adb push .\bin\MyTestsUIAutomatorTest.jar /data/local/tmp
cmd /c adb shell uiautomator runtest MyTestsUIAutomatorTest.jar -c xxxxxx.haylugar.uiautomator.src.SettingsActivityUIAutomatorTest
cmd /c adb shell uiautomator runtest HayLugarUIAutomatorTest.jar -c xxxxxx.haylugar.uiautomator.src.ParkingListActivityUIAutomatorTest
cmd /c adb shell uiautomator runtest HayLugarUIAutomatorTest.jar -c xxxxx.haylugar.uiautomator.src.ParkingDetailActivityUIAutomatorTest
使用 ant 构建时,uiautomator.jar 找不到对象:
src\ParkingDetailActivityUIAutomatorTest.java:3: error: package com.android.uiautomator.core does not exist
[javac] import com.android.uiautomator.core.UiObject;
显然,说明已根据 this and this 进行了更改,但我遵循了它们,但它们遗漏了一些东西(当 运行ning 测试说 "no tests found to run" 时,我收到错误消息)。无论如何,我只想 运行 我的测试和以前一样!我不想更改配置并浪费时间使用 Android SDK 团队的新想法...
已修复!
我需要手动编辑 build.xml 以覆盖 SDK 提供的 uibuild.xml 的编译和 dex 目标以正确完成工作,复制 requi我的项目结构中某处的红色库(uiautomator.jar 和 junit.jar):
<property name="jar.libs.dir" value="../../../../../../libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<path id="classpath">
<fileset dir="${jar.libs.absolute.dir}">
<include name="uiautomator.jar" />
<include name="junit-4.12.jar" />
</fileset>
</path>
<!-- version-tag: VERSION_TAG -->
<import file="${sdk.dir}/tools/ant/uibuild.xml" />
<!-- overwrite the compile target in uibuild.xml to include to external
jars -->
<target name="compile" depends="-build-setup, -pre-compile">
<javac encoding="${java.encoding}" source="${java.source}"
target="${java.target}" debug="true" extdirs="" includeantruntime="false"
destdir="${out.classes.absolute.dir}" bootclasspathref="project.target.class.path"
verbose="${verbose}" fork="${need.javac.fork}">
<src path="${source.absolute.dir}" />
<classpath refid="classpath" />
<compilerarg line="${java.compilerargs}" />
</javac>
</target>
<!-- overwrite the -dex target in uibuild.xml to include external jar files
into the target dex file. -->
<target name="-dex" depends="compile, -post-compile">
<dex executable="${dx}" output="${intermediate.dex.file}"
nolocals="@{nolocals}" verbose="${verbose}">
<path path="${out.classes.absolute.dir}" />
</dex>
</target>
</project>
我已经升级到最新版本的 Android Studio (1.5) 和 SDK,现在我的 UIAutomator 测试, 运行 来自 ant,不再工作了(他们曾经工作过,直到 Android Studio 1.0.x)。
这是我用来 运行 测试的脚本:
@echo off
cls
set ANDROID_HOME=C:\Users\xxxx\AppData\Local\Android\sdk
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_65
cmd /c ..\..\..\..\..\..\..\..\thirdparty\ant\bin\ant build
if ERRORLEVEL 1 goto end
:run
cmd /c adb push ..\..\..\..\..\..\..\app\libs\uiautomator.jar /data/local/tmp
cmd /c adb push .\bin\MyTestsUIAutomatorTest.jar /data/local/tmp
cmd /c adb shell uiautomator runtest MyTestsUIAutomatorTest.jar -c xxxxxx.haylugar.uiautomator.src.SettingsActivityUIAutomatorTest
cmd /c adb shell uiautomator runtest HayLugarUIAutomatorTest.jar -c xxxxxx.haylugar.uiautomator.src.ParkingListActivityUIAutomatorTest
cmd /c adb shell uiautomator runtest HayLugarUIAutomatorTest.jar -c xxxxx.haylugar.uiautomator.src.ParkingDetailActivityUIAutomatorTest
使用 ant 构建时,uiautomator.jar 找不到对象:
src\ParkingDetailActivityUIAutomatorTest.java:3: error: package com.android.uiautomator.core does not exist
[javac] import com.android.uiautomator.core.UiObject;
显然,说明已根据 this and this 进行了更改,但我遵循了它们,但它们遗漏了一些东西(当 运行ning 测试说 "no tests found to run" 时,我收到错误消息)。无论如何,我只想 运行 我的测试和以前一样!我不想更改配置并浪费时间使用 Android SDK 团队的新想法...
已修复!
我需要手动编辑 build.xml 以覆盖 SDK 提供的 uibuild.xml 的编译和 dex 目标以正确完成工作,复制 requi我的项目结构中某处的红色库(uiautomator.jar 和 junit.jar):
<property name="jar.libs.dir" value="../../../../../../libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<path id="classpath">
<fileset dir="${jar.libs.absolute.dir}">
<include name="uiautomator.jar" />
<include name="junit-4.12.jar" />
</fileset>
</path>
<!-- version-tag: VERSION_TAG -->
<import file="${sdk.dir}/tools/ant/uibuild.xml" />
<!-- overwrite the compile target in uibuild.xml to include to external
jars -->
<target name="compile" depends="-build-setup, -pre-compile">
<javac encoding="${java.encoding}" source="${java.source}"
target="${java.target}" debug="true" extdirs="" includeantruntime="false"
destdir="${out.classes.absolute.dir}" bootclasspathref="project.target.class.path"
verbose="${verbose}" fork="${need.javac.fork}">
<src path="${source.absolute.dir}" />
<classpath refid="classpath" />
<compilerarg line="${java.compilerargs}" />
</javac>
</target>
<!-- overwrite the -dex target in uibuild.xml to include external jar files
into the target dex file. -->
<target name="-dex" depends="compile, -post-compile">
<dex executable="${dx}" output="${intermediate.dex.file}"
nolocals="@{nolocals}" verbose="${verbose}">
<path path="${out.classes.absolute.dir}" />
</dex>
</target>
</project>