【问题标题】:Android UiAutomator test case jar file is not workingAndroid UiAutomator 测试用例 jar 文件不起作用
【发布时间】:2017-03-01 13:31:26
【问题描述】:

我一直在尝试使用 UiAutomator 工具编写一些 android 代码的工具测试用例。这个测试用例可以通过 android studio 运行,没有任何问题。但现在我想将此测试用例作为 jar 文件安装到设备中,并且需要通过命令行运行。我曾尝试使用以下链接来构建和部署 uiautomator 测试:

https://stuff.mit.edu/afs/sipb/project/android/docs/tools/testing/testing_ui.html#creating

build.xml 已生成,但执行命令“ant build”时显示错误:

 Android/Sdk/tools/ant/uibuild.xml:198: null returned: 1

之后我尝试使用 gradle build 而不是 ant build tool 使用此链接创建 jar 文件

http://wiliamsouza.github.io/#/2013/10/30/android-uiautomator-gradle-build-system

我已经从项目目录运行了“gradle build”命令并得到了输出;

 Building dex...
 :compileJava UP-TO-DATE
 :processResources UP-TO-DATE
 :classes UP-TO-DATE
 :jar
 :assemble
 :compileTestJava UP-TO-DATE
 :processTestResources UP-TO-DATE
 :testClasses UP-TO-DATE
 :test
 :check
 :build

 BUILD SUCCESSFUL
 Total time: 7.709 secs

但在“dist”文件夹中没有找到 jar 文件。在 build/libs 文件夹中找到已安装的 jar 文件,

adb push sample-0.1.jar /data/local/tmp/

然后尝试使用命令运行测试用例

 adb shell uiautomator runtest sample-0.1.jar -c com.test.uiautomator.sample.Sample

但它显示错误为:

   INSTRUMENTATION_RESULT: shortMsg=java.lang.RuntimeException
   INSTRUMENTATION_RESULT: longMsg=Didn't find 
   class"com.test.uiautomator.sample.Sample" 
   on path: DexPathList[[zip 
   file"/system/framework/android.test.runner.jar",
   zip file"/system/framework/uiautomator.jar", 
   zip file"/data/local/tmp/sample-0.1.jar"],
   nativeLibraryDirectories=[/vendor/lib, /system/lib]]
   INSTRUMENTATION_CODE: 0

有人对此有任何想法吗..我如何创建我的 uiautomator 测试用例的 jar 文件以及如何通过命令行运行它们..?

【问题讨论】:

    标签: command-line jar testcase android-uiautomator android-instrumentation


    【解决方案1】:

    找到解决方案!!!

    实际上我的要求是通过命令行运行工具测试用例(在我的情况下为 UiAutomator),为此不需要生成测试类的 jar 文件并将它们安装到设备上,而是我们可以创建单独的 apk测试用例包的文件,并以与安装应用程序 apk 文件相同的方式安装它们。然后运行 ​​adb 命令来执行测试用例。请检查下面的链接,其中有详细的解释。

    https://developer.android.com/studio/test/command-line.html#RunTestsCommand

    【讨论】:

      猜你喜欢
      • 2014-08-31
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多